Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
衆議院議員一覧から名前を抜き出して、ヤフー「つぶやき感情分析」で好悪を調べる
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