Skip to content

Instantly share code, notes, and snippets.

@naoranger
Created August 9, 2012 02:52
Show Gist options
  • Select an option

  • Save naoranger/3300490 to your computer and use it in GitHub Desktop.

Select an option

Save naoranger/3300490 to your computer and use it in GitHub Desktop.
nokogiri sample tenki
require 'nokogiri'
require 'open-uri'
url = "http://tenki.jp/"
doc = Nokogiri::HTML(open(url).read)
doc.xpath('//ul[@class="localList"]//li').each do |item|
# u = item.xpath('.//a').attribute('href')
puts item.xpath('.//a').text
# puts item.xpath('.//a/attribute::href').first
# puts item.search('a').attribute('href')
# doc2 = Nokogiri::HTML(open(url+u).read)
# doc2.xpath('//div[@id="weatherWaveBox"]//li').each do |item2|
# puts item2.xpath('.//a').text
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment