2009-12-31 7 views
5

मेरे पास doc.at('head/title').inner_html शीर्षक है जो & आता है और यह & होना चाहिए।Nokogiri रूबी में 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 &amp; Bar" 

मैं iconv या सीजीआई उपयोग करने के लिए की तरह नहीं करना चाहती:

>> require 'cgi' 
>> CGI.unescapeHTML(doc.at('head/title').inner_html) 
=> "Foo & Bar" 

वह बदसूरत और असुविधाजनक है।

उत्तर

7

उपयोग inner_html के बजाय content बजाय (एक्स) एचटीएमएल सादा पाठ के रूप में सामग्री प्राप्त करने के लिए।

irb(main):011:0> doc.at('head/title').content 
=> "Foo & Bar" 
संबंधित मुद्दे