5
나는 &
이라는 제목을 가지고 있으며 &
이어야합니다. 제목은 doc.at('head/title').inner_html
입니다.Nokogiri Ruby에서 HTML을 이스케이프 처리하는 방법 & &
내 원본 문서는 다음과 같습니다
<head><title>Foo & Bar</title></head>
만에 같이 나오는 다음
>> doc = Nokogiri::HTML.parse(file, nil, "UTF-8")
>> doc.at('head/title')
=> #<Nokogiri::XML::Element:0x..fdb851bea name="title" children=#<Nokogiri::XML::Text:0x..fdb850808 "Foo & Bar">>
>> doc.at('head/title').inner_html
=> "Foo & Bar"
내가 좋아하는의 iconv 또는 CGI를 사용하지 않으 :
>> require 'cgi'
>> CGI.unescapeHTML(doc.at('head/title').inner_html)
=> "Foo & Bar"
그것은 추악하고 불편합니다.