Answer the question
In order to leave comments, you need to log in
Python requests - how to log in?
Good day, I can not log in to the site, please help me with this problem.
import requests, json
s=requests.session()
headers={
'Accept': r'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Content-Length': '139',
'Content-Type': r'application/x-www-form-urlencoded',
'Cookie': r'_ym_uid=1571498676722467413; __gads=ID=57f78d3fcf46e74c:T=1588335737:S=ALNI_MZ-_Wd9Qf4NKQG8d0hj1KUSzr1tYA; _ym_d=1588335800; _ym_visorc_17789860=w; _ym_isad=2; xf_session=cd2d8d8e0210a86d4b73bd373883ac5b',
'Host': 'avtoved.guru',
'Origin': r'https://avtoved.guru',
'Referer': r'https://avtoved.guru/login',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': r'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36 OPR/67.0.3575.130',
}
data={
'login': '[email protected]',
'register': '0',
'password': '123456789',
'redirect': 'https://avtoved.guru/',
'remember': '1',
'cookie_check': '1',
'_xfToken':'' ,
}
login_url="https://avtoved.guru/login/"
test_url=r"https://avtoved.guru/attachments/3-jpg.18984/"
r=s.post(login_url,data=data,headers=headers)
testr=s.get(test_url)
print(testr.url, testr.text)
Answer the question
In order to leave comments, you need to log in
Oh, and you crammed so many things)
Here is the simplest code (you can simplify it further, but I'm too lazy):
import requests
headers = {'user-Agent': 'Mozilla/5.0'}
getUrl = 'https://avtoved.guru/login/'
postUrl = getUrl + 'login'
data = {'login':'логин','password':'пароль'}
ses = requests.session()
ses.get(getUrl,headers=headers)
response = ses.post(postUrl,headers=headers,data=data)
if 'LogOut' in response.text:
print('Login OK!')
else:
print('Login ERROR!')
Cookies must be received by visiting the authorization page within the session, after which they will be stored there. In your case, there is a question about the _xfToken parameter, is it most likely located on the authorization page and should it always be read from there?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question