ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
all other gems are freshly updated
I am trying to download text files from a site. The site requires
sign-up, sorry about that.
The following code hopefully gets elements I want.
I used Chrome console, “$x()” to confirm the xpath works for (at least)
Chrome.
But it does not gets the elements as Chrome does.
Could anyone tell me why?
require ‘rubygems’
require ‘net/http’
require ‘open-uri’
require ‘nokogiri’
url = ‘https://www.coursera.org/modelthinking/lecture/index’
xpather = ‘//div[@class=“item_resource”]’
html = Nokogiri::HTML(open(url))
i = 0
html.xpath(xpather).each do |link|
puts i
i += 1
end
Thanks in advance
soichi