lundi 13 février 2017

Can I initialize a Watir::Browser object with an open browser?

I am writing a small script with Watir to learn a bit about web scraping with scripting languages however the site I am using requires a login with 2 step verification.

I have the login process automated however currently I am manually inserting the authenticator code then continuing with my script to obtain the information and complete the tasks required.

Until I have automated the 2 step authentication it would be great if instead of opening a new browser and completing the login process I could just point a Watir::Browser object at an already logged in browser and start from there.

For reference this is the code I am already using to create my browser object:

require 'watir'

# Open ghost browser
browser = Watir::Browser.new(:chrome)

# Navigate to the scrape site
browser.goto("http://ift.tt/2kkxxrL")

# Set login information
browser.text_field(name: 'username').set "username"
browser.text_field(name: 'password').set "password"

# Login
browser.button(type: 'submit').click

# Manually enter verification code and continue script afterwards

Aucun commentaire:

Enregistrer un commentaire