Answer the question
In order to leave comments, you need to log in
How to use python,requests to login to a website?
I have been trying for the second day to write an authorization that works on this site. On others it works, but on this I don’t even see the reason for the failure. The site is powered by moodle.
import requests
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36'}
login_data = {'anchor': None,
'logintoken': None,
'username': 'guest',
'password': 'guest'
}
with requests.Session() as s:
url = 'http://www.uetk-spo.ru/login/index.php'
r = s.get(url, headers=headers)
soup = BeautifulSoup(r.content, 'html5lib')
login_data['logintoken'] = soup.find(
'input', attrs={'name': 'logintoken'})['value']
f = s.post(url, data=login_data, headers=headers)
print(f.content)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question