John
John

Reputation: 43

Web Scrape Vanguard Investment Account (login)

I am trying to automatically scrape my balance info from my Vanguard investment account. I am stuck trying to login to the account.

I've tried requests and mechanicalsoup and so far I have not been able to figure this out.

import mechanicalsoup



USERNAME = "myuser"
PASSWORD = "mypass"

OWNER="myemail"

start_page = "https://personal.vanguard.com/us/hnwnesc/nesc/LoginPage"
balance_page = "my balancepage"

r = mechanicalsoup.StatefulBrowser()
r.addheaders = [ 
("User-agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv 1.0) %s" %
               (OWNER)),
]


r.open(start_page)
r.select_form('LoginForm')
r['USER'] = USERNAME
r = br.submit()

r.select_form('LoginForm')
r['PASSWORD'] = PASSWORD
r = br.submit()

r = br.open(balance_page)

I am expecting to login and be directed to balance page, in order to automatically scrape balances to put into a dataframe.

EDIT here is a semi-working update using Selenium

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("https://investor.vanguard.com/my-account/log-on")
user_button = driver.find_element_by_id('USER')
user_button.send_keys('UsErId')
password_button = driver.find_element_by_id('PASSWORD')
password_button.send_keys('P@$$W0rd')

button = driver.find_element_by_id('login')
button.click()

Upvotes: 3

Views: 1161

Answers (0)

Related Questions