我想解析URL中的body屬性。如何在Rails中使用Nokogiri從URL獲取HTML主體?
例如:
url = 'http://rca.yandex.com/?key=rca.1.1.20140120T051507Z.3db118ab435efdff.6c84331313b6b7d66abd191410f72e0e1c3c8795&url=http://endtimeheadlines.wordpress.com/2014/01/17/think-tank-extraordinary-crisis-needed-to-preserve-new-world-order/#comment-36708?utm_source=twitterfeed&utm_medium=facebook[&callback=http://64.191.99.245:3023/posts][&full=1]'
當我嘗試:
page = Nokogiri::HTML(html)
我得到:
#<Nokogiri::HTML::Document:0x52fd6d6 name="document" children=[#<Nokogiri::XML::DTD:0x52fd1f4 name="html">, #<Nokogiri::XML::Element:0x52fc6aa name="html" children=[#<Nokogiri::XML::Element:0x5301f56 name="body" children=[#<Nokogiri::XML::Element:0x53018d0 name="p" children=[#<Nokogiri::XML::Text:0x53015f6 "http://rca.yandex.com/?key=rca.1.1.20140120T051507Z.3db118ab435efdff.6c84331313b6b7d66abd191410f72e0e1c3c8795&url=http://endtimeheadlines.wordpress.com/2014/01/17/think-tank-extraordinary-crisis-needed-to-preserve-new-world-order/#comment-36708?utm_source=twitterfeed&utm_medium=facebook[&callback=http://64.191.99.245:3023/posts][&full=1]">]>]>]>]>
我如何獲得這個URL裏面的屬性?
例如:page.css("div")
。我想從HTML body
中獲得價值。
我建議您閱讀爲Nokogiri提供的[「搜索」教程](http://nokogiri.org/tutorials/searching_a_xml_html_document.html)。這足以解釋你想要做什麼。 –
另外,定義「屬性」? body標籤的屬性通常是任何東西,比如'on_load'。你是指孩子節點還是內部HTML? –
我的回答有幫助嗎? –