Skip to content

Instantly share code, notes, and snippets.

@takuros
Created November 12, 2014 16:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuros/ef14021bd1d3f62c2bce to your computer and use it in GitHub Desktop.
Save takuros/ef14021bd1d3f62c2bce to your computer and use it in GitHub Desktop.
衆議院議員一覧から名前を抜き出して、ヤフー「つぶやき感情分析」で好悪を調べる
require 'nokogiri'
require 'open-uri'
require 'capybara'
require 'capybara/dsl'
require 'selenium-webdriver'
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = "http://realtime.search.yahoo.co.jp/"
include Capybara::DSL
def search(name)
puts name
visit ("search?tt=c&ei=UTF-8&fr=sfp_as&aq=-1&oq=&p=#{name}&meta=vc%3D")
sleep 5
save_screenshot("#{name}.png")
end
url = "http://www.shugiin.go.jp/internet/itdb_annai.nsf/html/statics/syu/1giin.htm"
html = open(url).read.encode("UTF-8","Shift_JIS")
doc = Nokogiri::HTML(html)
doc.xpath("//*[@id='sh1body']//td[@class='sh1td5']/tt/a").each do |element|
name = element.text.gsub(/君| /,"")
search(name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment