0

Im trying to login to a website via a script but when I print the websites html content, but I cant see any of the data available after login... Can someone tell what I am missing? Thank you!

def main():
headers = {
    "User-Agent":
        "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36",
}

s = requests.session()
s.headers.update(headers)
s.get('https://www.e-ams.at/eams-sfa-account/p/index.jsf')

# Generate the post data
data = {
    'url': 'https://www.e-ams.at/eams-sfa-account/p/index.jsf',
    'j_username': 'username',
    'j_password': 'password'
}

# Perform the post request
r = s.post('https://www.e-ams.at/eams-sfa-account/p/index.jsf', data=data)

# Try to get data only available after login
r = s.get('https://www.e-ams.at/eams-sfa-account/p/EsaSBasisdaten.jsf?eamsTrack=1524234335254')
print(r.url)
print(r.text)
print(r.status_code)
Constantin M
  • 119
  • 1
  • 4
  • 18

1 Answers1

0

If it is not part of the html form inputs, specifying the url in data dict is not correct. Your request must be as follows:

data = {
    'j_username': 'username',
    'j_password': 'password'
}
r = s.post('https://www.e-ams.at/eams-sfa-account/p/index.jsf', data=data)

Generally speaking all the input tags of the form (both visible and hidden) must be included in the data dict

AntoG
  • 833
  • 1
  • 10
  • 16
  • Thanks for your reply! No idea why I tried to include the URL in the data but I removed it thanks :-) I just tried to check the source code once logged in, and the application always tells me to use the inbuilt buttons to navigate through the app... What kind of files are jsf files? – Constantin M Apr 20 '18 at 14:44
  • I checked on the website and the url to include in the post request is: `https://www.e-ams.at/eams-sfa-account/p/j_security_check`. Please retry with `r = s.post(https://www.e-ams.at/eams-sfa-account/p/j_security_check', data=data)` – AntoG Apr 20 '18 at 14:50
  • I tried that, but seemed to get the exact same response like before... :/ Apparently they append a date.getTime() and include it in their urls after login. I will try to recreate it and also post the getTime() param with the url. Example: if(param == 'demo'){ demoSfa(); }else if(param == 'nachrichten'){ window.location.href = link + '/p/EsaSPostkorbEingang.jsf?eamsTrack=' + date.getTime(); – Constantin M Apr 20 '18 at 15:03
  • The thing is, that I want to post data into the application after login. Would it work to login manually and then post to the app with python? – Constantin M Apr 20 '18 at 15:14
  • you can but you have to pass cookies between the browser and the requests library as explained in the link [link]https://stackoverflow.com/questions/42087985/python-requests-selenium-passing-cookies-while-logging-in – AntoG Apr 20 '18 at 15:34