我試圖讓使用此表的XPath的一個表中的一些值,但它只返回[]
(空):在Nokogiri中使用XPath獲取HTML表值?
require 'nokogiri'
require 'open-uri'
url = "http://riopretrans.com.br/linhas.php?ln=106"
doc = Nokogiri::HTML(open(url))
doc.xpath("html/body/table[1]/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[2]/td/div/table[1]/tbody/tr[3]/td/div/div/center/font/table").each do |lines|
puts lines.content
end
我發現表的XPath的使用Firebug,所以我認爲這是正確的。
任何人都可以幫助我嗎?
所有這些?因爲在html文件中,所有這些都是指定的(由程序員編寫)。 – vhbsouza 2013-04-26 18:27:19
它繼續錯誤。 :( – vhbsouza 2013-04-26 18:35:01
你的'table#foo'和''div.bar table''很有意思。你能給我一個我能看到這麼短的手的源碼嗎? – 2013-04-26 19:04:33