Created
December 17, 2017 02:16
-
-
Save wppurking/3cee5fa9e04125ca3e6de6962279a76e to your computer and use it in GitHub Desktop.
使用 capybara 以及 selenium_chrome 登陆 Twitter 后台
This file contains hidden or 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 'capybara' | |
require 'selenium-webdriver' | |
require 'thread/pool' | |
pool = Thread.pool(3) | |
Capybara.threadsafe = true | |
Capybara.default_driver = :selenium_chrome | |
#Capybara.default_driver = :selenium_chrome_headless | |
TT = 'https://twitter.com' | |
def visit_twitter | |
# 启动一个 session | |
puts '=====' | |
ss = Capybara::Session.new(Capybara.default_driver) | |
ss.visit(TT) | |
ss.fill_in('signin-email', with: 'email_address') | |
ss.fill_in('signin-password', with: 'password') | |
ss.click_on('Log in') | |
ss.save_screenshot("./twitter_login_#{rand(10)}.png", full: true) | |
ss.driver.quit | |
end | |
2.times { | |
pool.process do | |
visit_twitter | |
end | |
} | |
pool.shutdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment