Take a look at this page: http://finviz.com/quote.ashx?t=AAPL
The XPath
(//*[contains(concat(' ', @class, ' '), ' snapshot-table2 ')]/tbody/tr/td[text() = 'Index']/following::td)[1]/b
should spit out S&P 500
, and when I try it out in the JavaScript console, it does. However, when I try using Nokogiri with Ruby, it returns an empty array.
Here's the full code:
url = "http://finviz.com/quote.ashx?t=#{ticker}"
data = Nokogiri::HTML(open(url))
xpath = "(//*[contains(concat(' ', @class, ' '), ' snapshot-table2 ')]/tbody/tr/td[text() = '#{datapoint}']/following::td)[1]/b"
data.xpath(xpath)
data.xpath(xpath)
returns []
Any ideas?