Skip to content

Instantly share code, notes, and snippets.

@tmtysk
Created August 26, 2010 04:04
Show Gist options
  • Save tmtysk/550782 to your computer and use it in GitHub Desktop.
Save tmtysk/550782 to your computer and use it in GitHub Desktop.
外部サイトをスクレイピングしてSWFタグ番号からタグ名のHashをつくる
# vim: set fileencoding=utf-8 filetype=ruby ts=2 :
# making Hash object of SwfTagType(code) to SwfTagName by scraping on external url.
require 'nokogiri'
require 'open-uri'
require 'pp'
TARGET_URI = "http://example.com/swf_tags"
doc = Nokogiri::HTML(open(TARGET_URI))
swfs = Hash.new
doc.css("table.views-table tbody tr").each do |tr|
k = tr.css("td.views-field-field-swf-tag-number-value").first.content.strip.gsub(/\./, "")
v = tr.css("td.views-field-title a").first.content.strip
swfs[k] = v
end
pp swfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment