当前位置:网站首页>Cookie simulation login "recommended collection"
Cookie simulation login "recommended collection"
2022-07-30 14:10:00 【Full stack programmer webmaster】
Hello everyone, meet again, I'm your friend Quanstack Jun.
I am using requests.get(url,headers,cookies) in python here.
Where headers and cookies are both in dictionary form.The role of headers is to simulate a browser and tell the server that I am not a crawler.The role of cookies is to impersonate a user and tell the server that I am not a robot and that I am a user of so-and-so.
Take Zhihu as an example, headers can use templates:
headers = { 'Host': 'www.zhihu.com', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding': 'gzip, deflate', 'Referer': 'http://www.baidu.com', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0',
}
Then there are cookies. For cookies, I log in in the browser first, then look for the cookie, and copy the content into txt. Then the crawler directly reads the txt and converts it into a dictionary.The specific process is as follows (take google browser as an example):
1. Log in to Zhihu: http://www.zhihu.com
2. Open browser settings->advanced->privacy settings and security->content settings->cookies->view all cookies and website data
3. Search zhihu and get the following picture
Open zhihu.com, as shown below
These four are the keys of the cookie. There is a value in the down arrow, and a dictionary can be created based on this.(Note: Some values contain double quotes, so you can't lose them)
When visiting, html=requests.get("https://www.zhihu,com",headers=headers,cookies=cookies)
content=html.text
Publisher: Full-stack programmer, please indicate the source: https://javaforall.cn/128957.htmlOriginal link: https://javaforall.cn
边栏推荐
- CF780G Andryusha and Nervous Barriers
- AT4108 [ARC094D] Normalization
- 近两年激光雷达运动物体分割论文阅读小结
- redis6.0 源码学习(五)ziplist
- [ARC092D] Two Faced Edges
- [VMware virtual machine installation mysql5.7 tutorial]
- 43.【list的简单属性】
- Classic test interview questions set - logical reasoning questions
- Flask框架——Flask-Mail邮件
- 无代码开发平台全部应用设置入门教程
猜你喜欢

How awesome is the "12306" architecture?

jsArray数组复制方法性能测试2207300823

业内人士真心话:只会测试没有前途的,我慌了......

还在说软件测试没有中年危机?9年测试工程师惨遭淘汰

jsArray数组复制方法性能测试2207292307

LeetCode二叉树系列——116.填充每个节点的下一个右侧指针

Data Middle Office Construction (5): Breaking Enterprise Data Silos and Extracting Data Value

05 | 后台登录:基于账号密码的登录方式(下)

逻辑漏洞----权限类漏洞

cpu/CS and IP
随机推荐
MQTT网关读取西门子PLC数据传输到阿里云平台案例教程
sql中ddl和dml(sql与access的区别)
第十四天笔记
Shell变量与赋值、变量运算、特殊变量、重定向与管渠
LeetCode二叉树系列——102.二叉树的层序遍历
(论文翻译]未配对Image-To-Image翻译使用Cycle-Consistent敌对的网络
LeetCode二叉树系列——144.二叉树的最大深度
UPC2022暑期个人训练赛第19场(B,P)
pytorch学习记录(六):循环神经网络 RNN & LSTM
激光雷达点云语义分割论文阅读小结
43.【list链表的定义及初始化】
shell 编程规范与变量
打破原则引入SQL,MongoDB到底想要干啥???
CF780G Andryusha and Nervous Barriers
Simple understanding of Precision, Recall, Accuracy, TP, TN, FP, FN
NFTScan 与 PANews 联合发布多链 NFT 数据分析报告
shell script flow control statement
ENVI Image Processing (6): NDVI and Vegetation Index
ARC117E Zero-Sum Ranges 2
#第九章 子查询课后习题