Skip to content

Instantly share code, notes, and snippets.

@kumagi
Last active March 11, 2016 02:54
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 kumagi/0457c38dd9fa0e8437fe to your computer and use it in GitHub Desktop.
Save kumagi/0457c38dd9fa0e8437fe to your computer and use it in GitHub Desktop.
検索は応援になる
require 'selenium-webdriver'
class KensakuOuen
def initialize()
@driver = Selenium::WebDriver.for :firefox
end
def search(keyword)
begin
@driver.manage.delete_all_cookies
@driver.get "http://www.yahoo.co.jp"
input = @driver.find_elements(:id => "srchtxt", :tag_name => "input")[0]
input.send_keys(keyword)
btn = @driver.find_elements(:id => "srchbtn", :tag_name => "input")[0]
btn.click
ret = @driver.page_source
rescue => e
p e
ensure
sleep 1
end
ret
end
end
k = KensakuOuen.new
loop do
k.search("3.11")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment