Created
November 12, 2014 16:40
-
-
Save takuros/ef14021bd1d3f62c2bce to your computer and use it in GitHub Desktop.
衆議院議員一覧から名前を抜き出して、ヤフー「つぶやき感情分析」で好悪を調べる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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