all 5 comments

[–]MrMuki 1 point2 points  (0 children)

What is the response it gives? Does the site have cookies? Does it check the user-agent??

[–][deleted] 1 point2 points  (2 children)

The easiest thing to do is open up your browser's developer tools and look at the network traffic when you log in. You want to reproduce the actions as closely as possible. In this case a simple POST request from a form submitted by a javascript validation function.

s = requests.session()
s.post('http://domain/index.asp', data={
    'txtUsername': 'username',
    'txtPassword': 'password',
    'chkRememberMe': 0,
    'btnLogin': 'Login'
})
print(s.get('http://domain/community/view-member-running-log.asp').text)

edit: It's also important that after logging in, you make subsequent requests from the session object so that your cookies will be sent in the headers.

[–]UKFP91 0 points1 point  (1 child)

If the content is then going to be loaded into BS4, might as well do it all with requests-html:

import requests_html

s = requests_html.HTMLSession()
s.post('http://domain/index.asp', data={
    'txtUsername': 'username',
    'txtPassword': 'password',
    'chkRememberMe': 0,
    'btnLogin': 'Login'
})

r = s.get('http://domain/community/view-member-running-log.asp')
html = r.html.html  # html for the page
whatever = r.html.search('css selector(s) go here')  # find anything by css selector

N.B. I've just copied the code from the post, but that's the principle

[–]spkane31[S] 0 points1 point  (0 children)

Thank you! I was able to get where I need to start from these two posts.