Last active
October 6, 2017 06:04
-
-
Save sanryuu/c5e0081d5cd6a80d619c to your computer and use it in GitHub Desktop.
CapybaraとSeleniumを使ってGoogle検索するサンプルコード ref: http://qiita.com/sanryuu/items/5b1b4794f5fd3b26679c
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
#! /usr/bin/env ruby | |
require "capybara" | |
require "selenium-webdriver" | |
Capybara.current_driver = :selenium | |
module Crowler | |
class Google | |
include Capybara::DSL | |
def hit_num keyword | |
visit URI.escape("https://www.google.co.jp/search?q=" + keyword) | |
result_status = all("#resultStats")[0] | |
unless result_status.nil? | |
result_status.text.match(/(\d+,)*\d+/)[0].gsub(",","").to_i | |
else | |
0 | |
end | |
end | |
end | |
end | |
blowser = Crowler::Google.new | |
print blowser.hit_num "Capybara Selenium" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment