How to log into a browser prompt (Picture below) with a python request?

Viewed 205

Chrome Browser Prompt to Sign in

First, please recognize there are many answered questions about forum type logins. This is different, as this prompt does not appear in the HTML or JS.

I'm trying to automate some web scraping.

I would like to use something like the following to log into the page:

login_URL = 'https://somewebsite.com'
page_URL = 'https://somewebsite.com'

payload{
    'Username': 'yourusername',
    'Password': 'yourpassword'
}

with requests.Session() as session:
    post = session.post(login_URL, data=payload)
    r = session.get(page_URL)
    print(r.text)

Based on my research, this doesn't seem possible since the prompt appears before the page even loads.

Any insights would be helpful!

1 Answers

From the comments it becomes clear that that was a browser's response to 401 Unauthorized.
So, to login you need to do this:

session.get('https://yourusername:yourpassword@somewebsite.com')
Related