html - Python - 网站登录 - 抓取 CSRF 令牌失败
问题描述
我是新来的,也是编程新手。我正在尝试登录 URL =' https://www.esselunga.it/area-utenti/applicationCheck?AppName=esselungaEcommerce&daru=https%3A%2F%2Fwww.esselungaacasa.it%3A443%2Fecommerce%2Fnav%2Fauth% 2Fsupermercato%2Fhome.html%3F&loginType=light '。
当我检查网页时,我清楚地看到了 HTML 中的 csrf_token ('name'='X-CSRF-TOKEN') 及其值;但是,当我用 BeautifulSoup 提取它时,它不可用。我检查了内容(requests.session().get(url).content),csrf_token 行消失了,在“查看页面源”中也是如此。
是否仍然可以检索 CSRF,或者无论如何都可以在没有它的情况下登录?
谢谢!
import requests
from bs4 import BeautifulSoup
## Here below the data collected from the Network source view, once i logged in. Form Data section:
login_data= {'username':'xxxx', # <- instead of xxx put your username
'password':'xxxx', # <- instead of xxx put your psswrd
'daru':'xxx', # <- data taken from the FORM DATA
'dare':'xxxx', # <- data taken from the FORM DATA
'appName': 'xxx'} # <- data taken from the FORM DATA
with requests.Session() as s:
login_url="xxx" #<- the URL is above in the comment
result = s.get(login_url)
print (result.content) # here you can see the X-CSRF-TOKEN is not extracted.
soup = BeautifulSoup(result.content,'html5lib')
p = soup.find('input', attrs={'name':'X-CSRF-TOKEN'})['value'] # I can see it in the inspection tab
print(p) # csrf token is not in the content, neither when i check the 'view page source'. But in the inspection I see it!
## I am stuck at the above line. The following would be:
login_data['X-CSRF-TOKEN']) = p
r = s.post(login_url,data=login_data)
print(r.content)
解决方案
推荐阅读
- python - 从序列中创建所有固定长度的不连续子序列
- sql-server - SQL Server:根据同一个表中的两个布尔参数选择记录
- php - 我的用户可以上传图像,每个用户应该有一个用于存放他的图像的文件夹,还是应该将所有图像存储在 1 个文件夹中?
- yii2 - 为什么模型的公共功能中的规则不能正确完成其工作?
- javascript - 在 Cloud Firestore 中返回文档
- unity3d - 向另一个方向旋转统一游戏对象
- azure - 部署到 Azure 服务结构时无法访问 Spring Boot 端口
- python - Shopify API JSON Feed / Limit 250 和 Pages / GET 每次不是下一页时都会提取完全相同的记录
- java - Arrays.sort() 对于相同输入的 int[] 和 String 的工作方式不同,为什么?
- c++ - D3DLVERTEX中关于Tu和Tv的C++参数