Skip to content

Instantly share code, notes, and snippets.

@shirayuca
Created December 23, 2014 13:51
Show Gist options
  • Save shirayuca/d3c0d4b9619e8860e689 to your computer and use it in GitHub Desktop.
Save shirayuca/d3c0d4b9619e8860e689 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'nokogiri'
url = 'http://www.vorkers.com/field.php?ind_code=0003&f_code=0025'
charset = nil
html = open(url) do |f|
charset = f.charset # 文字種別を取得
f.read # htmlを読み込んで変数htmlに渡す
end
# htmlをパース(解析)してオブジェクトを作成
doc = Nokogiri::HTML.parse(html, nil, charset)
doc.xpath('//tr').each_with_index do |node,index|
if index == 0
next
end
puts [
node.xpath('.//td[@class="comp_name"]').text,
node.xpath('.//td[@class="comp_name"]/a').attribute('href').value,
node.xpath('.//td[@class="num_answer"]').text,
node.xpath('.//td[@class="total_score"]/span[@class="score_up"]').text
].join(',')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment