I am trying to login to Sherwin Williams contractor website using mechanical soup. I had this script working for quite some time, and then something changed making it so that I was no longer able to enter my login credentials on the login page. Here was my script:
import mechanicalsoup, requests, csv, os.path, pathlib
from datetime import datetime
today = datetime.today().strftime('%m-%d-%Y')
#create stateful browser
browser = mechanicalsoup.StatefulBrowser(
soup_config={'features': 'lxml'},
raise_on_404=True,
user_agent='MyBot/0.1: mysite.example.com/bot_info',
)
user = ###
pw = ###
# use browser to open link
browser.open("https://www.sherwin-williams.com/painting-contractors")
browser.follow_link("#Header_GlobalLogin_signInQuickLink")
form = browser.select_form()
form.set_input({"login": user, "password": pw})
print(form.print_summary())
browser["logonId"] = user
browser["logonPassword"] = pw
# print summary for review
resp = browser.submit_selected()
print('login submitted')
print(browser.url)
#click the invoices page
click_invoice_link = browser.open("https://www.sherwin-williams.com/InvoiceListView?catalogId=11052&storeId=10151&langId=-1")
csv_href = 'https://www.sherwin-williams.com/InvoiceListView?d-1337519-e=1&catalogId=11052&6578706f7274=1&storeId=10151&langId=-1'
page = browser.page
messages = page.find("span", class_="export csv")
resp = browser.session.get(csv_href)
resp.raise_for_status() # raise an exception for 404, etc.
surface = ''
desktop = ''
if pathlib.Path(surface).exists() :
#if surface condition true:
print('Found surface path')
save_path = surface
completeName = os.path.join(save_path, today + ".csv")
with open(completeName, 'wb') as outf:
outf.write(resp.content)
elif pathlib.Path(desktop).exists() :
#if surface condition true:
print('Found desktop path')
save_path = desktop
completeName = os.path.join(save_path, today + ".csv")
with open(completeName, 'wb') as outf:
outf.write(resp.content)
I've since tinkered with the script but I used to be able to follow the csv_href link once I was on the right page and download my invoices. I am currently unable to select the correct html field to enter my login credentials. Can somebody help me figure out how to properly fill the login fields using mechanical soup and get past the login page?