当前位置:网站首页>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
边栏推荐
- No-code development platform all application settings introductory tutorial
- 高性能数据访问中间件 OBProxy(三):问题排查和服务运维
- 简单理解精确率(Precision),召回率(Recall),准确率(Accuracy),TP,TN,FP,FN
- CF780G Andryusha and Nervous Barriers
- 3年软件测试经验面试要求月薪22K,明显感觉他背了很多面试题...
- [ARC092B] Two Sequences
- 学习笔记——七周成为数据分析师《第一周:数据分析思维》
- Eleven BUUCTF questions (06)
- [ARC092D] Two Faced Edges
- Mac Brew 安装PHP
猜你喜欢
随机推荐
jsArray array copy method performance test 2207300823
ARC115F Migration
Flask框架——Sijax
MQTT网关读取西门子PLC数据传输到阿里云平台案例教程
学习笔记——七周成为数据分析师《第二周:业务》:业务分析指标
LeetCode二叉树系列——144.二叉树的最小深度
VLAN实验
【高等数学】【7】二重积分
ARC117E零和范围2
永州动力电池实验室建设合理布局方案
UPC2022暑期个人训练赛第19场(B,P)
手把手教你写让人眼前一亮的软件测试简历,收不到面试邀请算我输
Flask框架——Flask-Mail邮件
05 | login background: based on the password login mode (below)
还在说软件测试没有中年危机?9年测试工程师惨遭淘汰
LeetCode二叉树系列——199二叉树的右视图
产品年度营销计划书
【软考软件评测师】基于规则说明的测试技术上篇
No-code development platform all application settings introductory tutorial
jsArray数组复制方法性能测试2207300823



![[VMware virtual machine installation mysql5.7 tutorial]](/img/eb/4b47b859bb5695c38d48c8c01c9da0.png)





