当前位置:网站首页>cookie模拟登录「建议收藏」
cookie模拟登录「建议收藏」
2022-07-30 13:40:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
我这里使用的是python中的requests.get(url,headers,cookies).
其中headers和cookies都是字典形式。headers作用是模拟浏览器,告诉服务器我不是爬虫。cookies作用是模拟用户,告诉服务器我不是机器人,我是某某用户。
以知乎为例,headers可以用模板:
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’,
}
然后就是cookies,cookies我是先在浏览器中登录,然后去找cookie,并把内容复制到txt中,到时候爬虫直接去读取txt,并转换成字典。具体过程如下(以google浏览器为例):
1、登录知乎:http://www.zhihu.com
2、打开浏览器设置—>高级—>隐私设置和安全性–>内容设置–>cookie–>查看所有cookie和网站数据
3、搜索zhihu,得到下图
打开zhihu.com那个,如下图
这四个就是cookie的键,打开向下的箭头里面有值,根据这个建立字典即可。(注意:有的值包含着双引号,不能搞丢了)
访问时,html=requests.get(“https://www.zhihu,com”,headers=headers,cookies=cookies)
content=html.text
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128957.html原文链接:https://javaforall.cn
边栏推荐
- shell script flow control statement
- 一本通循环结构的程序设计第一章题解(1)
- 阿里 P7 到底是怎样的水平?
- R语言筛选时间序列数据的子集(subset time series data)、使用window函数筛选连续日期时间范围内的数据(start参数和end参数分别指定起始和结束时间)
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、width参数自定义箱图中箱体的宽度
- js背景切换时钟js特效代码
- Shell变量与赋值、变量运算、特殊变量、重定向与管渠
- 【Pytorch】如何在关闭batch-norm的同时保持Dropout的开启
- [ARC092B] Two Sequences
- 网络安全——lcx的使用
猜你喜欢

What is the level of Ali P7?

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

Logic Vulnerability----Permission Vulnerability

戴墨镜的卡通太阳SVG动画js特效

ENVI Image Processing (6): NDVI and Vegetation Index
SQL 26 calculation under 25 years of age or older and the number of users

el-table中el-table-column下的操作切换class样式

There is a risk of water ingress in the battery pack tray and there is a potential safety hazard. 52,928 Tang DMs are urgently recalled

如何判断自己是否适合IT行业?方法很简单

jsArray数组复制方法性能测试2207292307
随机推荐
[论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
AT4108 [ARC094D] Normalization
剑指 Offer 05. 替换空格
[ARC092B] Two Sequences
TaskDispatcher源码解析
No-code development platform application visible permission setting introductory tutorial
jsArray数组复制方法性能测试2207300823
svg波浪动画js特效代码
LeetCode二叉树系列——102.二叉树的层序遍历
[ARC092B] Two Sequences
jsArray array copy method performance test 2207300823
六面蚂蚁金服,抗住面试官的狂轰乱炸,前来面试复盘
R语言使用方差分析ANOVA比较回归模型的差异、anova函数比较两个模型并报告它们是否存在显著差异(两个模型的数据相同,一个模型使用的预测特征包含另外一个模型的特征)
PyQt5快速开发与实战 8.6 设置样式
Apache Log4j2漏洞
判断链表是否有环
How awesome is the "12306" architecture?
qq udp tcp机制
[C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?