How to get the page after authentication with requests?

Asked

Viewed 79 times

0

I am trying to make a web scraping in python. My code is as follows:


import requests from bs4 import Beautifulsoup Session = requests. Session() payload = {'username':'[xxxxx]', 'password':'[xxxxx]' } url = 'http://portalservicos.jucec.ce.gov.br/auth/realms/Portal_Interno/login-actions/authenticate?code='
'Nmid0kphhhbiuuefrayvtqihfq8pgnhoun0tr8rtp0m.97621447-8553-43f8-B505-bee4d488dc16&Execution=e489f6d8-a24c-'
'400b-A121-b4dd05035c47' s = Session.post(url,data=payload,headers = Dict(referer=url))


The answer is 200, but the page obtained is the same as before login.

Include that line:


page=Session.get('http://portalservicos.jucec.ce.gov.br/srm/principal.jsf') Soup = Beautifulsoup(page.text, 'html.parser')


It also did not work, it is as if the login had not been done, The content of the page is the same as before the login.

Can someone help me?

  • The parameters code and execution are dynamic. First scratch the login page, take the form action and submit the login for that action in it session. This may not be the solution, but it’s where you should start.

1 answer

-1

Response that gives you status 200 also has a url property

take the test:

if response.history:
print("Request was redirected")
for resp in response.history:
    print(resp.status_code, resp.url)
print("Final destination:")
print(response.status_code, response.url)

Else: print("Request was not redirected")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.