Skip to content

Instantly share code, notes, and snippets.

@tenten0213
Created March 13, 2014 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenten0213/9524714 to your computer and use it in GitHub Desktop.
Save tenten0213/9524714 to your computer and use it in GitHub Desktop.
qiitaの自分のストックをスクレイピング
require 'open-uri'
require 'nokogiri'
# proxy設定
proxy = "http://YOUR_PROXY:8080"
proxy_user = "PROXY_USER"
proxy_pass = "PROXY_PASS"
options = { proxy_http_basic_authentication: [proxy, proxy_user, proxy_pass] }
# スクレイピング先のURL
url = 'http://qiita.com/tenten0213/stock'
charset = nil
html = open(url, options) do |f|
charset = f.charset
f.read
end
doc = Nokogiri::HTML.parse(html, nil, charset)
doc.xpath('//div[@class="activities"]/article').each do |node|
puts node.css('h1').inner_text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment