День добрый.
Пробую пройти авторизацию на WEB ресурсе.
Ресурс взаимодействует с CSRF При каждом обращении требуется получить значения CSRF.
Для это можно воспользоваться Cookie's.
Как составить запрос POST. Вложив в него нужные данные HEADERS user_agent и передать значения пользователя а именно user and passwd. С использованием редиректа страницы.
Имеется следущий код для пайтона.
import requests
import time
from lxml import html
import re
import json
source = ['https://chatur', 'bate.com/auth/login/']
print(source[0]+source[1])
print(source[0]+"bate.com")
response = requests.get(source[0]+source[1])
#print(response.content)
tree = html.fromstring(response.content)
csrf = tree.xpath('//*[@id="main"]/div/div/form/input/@value')
print(csrf[1])
print(response.headers.get('Set-Cookie'))
jes = response.headers.get('Set-Cookie')
ksrf = response.headers.get('Set-Cookie')
result = re.findall(r'csrftoken=\w+', ksrf)
results = re.findall(r'\w+', str(result))
print(csrf[1], results[1])
print(response.headers.get('Server'))
###############
###############
url = source[0]+source[1]
headers = {
#':authority': 'bate.com',
#':method': 'POST',
#':path': '/auth/login/',
#':scheme': 'https',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'ru,en;q=0.9',
'cache-control': 'max-age=0',
'content-length': '122',
'content-type': 'application/x-www-form-urlencoded',
'cookie': ksrf,
'origin': source[0]+'bate.com',
'referer': source[0]+source[1],
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 YaBrowser/19.12.2.252 Yowser/2.5 Safari/537.36'}
data = 'next=&csrfmiddlewaretoken={csrf[1]}}&username=thorix0&password=Lovacska00&g-recaptcha-response=03AGdBq24NntPLGWn_DrO_3PDWYzO3Ak8bcJnGfj5jj5ThGAQu51lHYDroH11vzDIgVU-8WlbdSqbQMA3n8ERyB3oDq_uY2Kkpgti_rnQeuAC9Q4sBlmYJFtoh7St4um6bjrSADh_TIIlinEj2t8udNAPhxevlowvOvyRmGxM2oIjhJHkPRSQin8Tzsnfu-bOeuISY3_jAI1Q5LR2j_SqhmqhXCLmcG5pGKYgJ2Szyi5AqNhmelhx1dYTvnUdLPHzq-bhSDepzVNBi_rJflsoxnJloP4CdA4j-Vw5gcHz5snLUpSwgt8-uN1Q3k2cUZs_Gx3H57w7EnyscjQIal67vcv1vaW33s5ciS7bgHfrL0EtzW7Cir97I9ZW96drv-pLSTLabzBcOJu5P'
res = requests.post(url, data=data, headers=headers, )
print(res.status_code)
print(res.history)
print(str(res.text))
Понять что отвечает сервер на такой запрос трудно.
Приходит такое
£
в кодировке ISO 1985