Im trying to login to a website and keep a session so I can post multiple data on to it later on. Im using a with statement to do that. Im having trouble posting my login credentials, I'm trying to do something similar as the answer here https://stackoverflow.com/a/15794896/12203664 specifically when posting the login although it was from 8 yrs ago.
I get an AttributeError: 'Response' object has no attribute 'post'. I think it is because session now does not have a post method? I'm not sure how to go about that. Below is a sample of what I have so far.
import requests
from bs4 import BeautifulSoup
url="https://website.com/login"
def login_payload(html):
login_payload = {'user': 'USER',
'pass': 'PW',
'login': loginValue(html) }
return login_payload
def loginValue(html):
soup = BeautifulSoup(html, 'html.parser')
hidden_tags = soup.find_all(type='hidden')
for tag in hidden_tags:
return tag.get('value')
with requests.Session() as s:
s = s.get(url) #to get loginvalue
s = s.post(url, data = login_payload(s.text))
print(s.text) #check if login is successful