I'm XPath-ing through a web page with NOKOGIRI. I'm familiar with XPath, but I cannot figure out why my XPath fails to pick up the specific row. See the ruby code.
I used FireBug XML to validate my XPath, so I am 99% sure my XPath is correct.
require 'nokogiri'
require 'open-uri'
@searchURL = 'http://www.umn.edu/lookup?UID=smit4562'
@xpath = '//html/body/p/table/tbody/tr/td[2]/table/tbody/tr[2]'
doc = Nokogiri::HTML(open(@searchURL))
puts 'row should be = Email Address: [email protected]'
puts '=> ' + doc.xpath(@xpath).to_s
puts 'is row emppty?'
puts '=> ' + doc.xpath(@xpath).empty?().to_s
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…