当前位置:网站首页>2.网络资源访问工具:requests
2.网络资源访问工具:requests
2022-07-30 20:18:00 【饮马翰海】







import requests
headers={
'User-Agent': 'Mozilla/5.0'
}
url="https://book.douban.com/latest?subcat=%E5%B0%8F%E8%AF%B4"
r=requests.get(url=url,headers=headers)
print(r) # <Response [200]>
print(type(r)) # <class 'requests.models.Response'>
print(r.status_code) # 200
print(r.headers)
print(r.headers['pragma']) # no-cache
print(r.text) # 查看网页源代码
print(r.encoding) # utf-8
print(r.apparent_encoding) # utf-8 查看真实编码
''' 如果遇到真实编码,加上这一句就可以: r.encoding=r.apparent_encoding # 设置真实编码 '''





clst = cookies.split('; ')
dic_c = {
}
for i in clst:
dic_c[i.split('=')[0]] = i.split('=')[1]
print(dic_c)
r = requests.get(url=url, headers=dic_h, cookies=dic_c)
print(r.status_code) # 200
print(r.text) # 输出网页源代码
soup = BeautifulSoup(r.text, 'lxml') # 使用lxml进行解析
a = soup.find('li', class_="nav-user-account").find('a').text # class_ :如果写类名的话这个class后面有一个下划线
print(a) # 赤~~的帐号
print(type(a)) # <class 'str'>
边栏推荐
- FFmpeg —— 裁剪视频(含音视频),不需编解码(附完整源码)
- 【无标题】多集嵌套集合使不再有MultipleBagFetchException
- 推荐系统-排序层-模型(一):Embedding + MLP(多层感知机)模型【Deep Crossing模型:经典的Embedding+MLP模型结构】
- Apple Silicon配置二进制环境(一)
- 推荐系统:概述【架构:用户/物品特征工程---->召回层---->排序层---->测试/评估】【冷启动问题、实时性问题】
- Interviewer Ali: Describe to me the phenomenon of cache breakdown, and talk about your solution?
- 多线程获取官方汇率
- 365天挑战LeetCode1000题——Day 044 按公因数计算最大组件大小 并查集
- 推荐系统:实时性【特征实时性:客户端实时特征(秒级,实时)、流处理平台(分钟级,近实时)、分布式批处理平台(小时/天级,非实时)】【模型实时性:在线学习、增量更新、全量更新】
- Recommended system: cold start problem [user cold start, item cold start, system cold start]
猜你喜欢
随机推荐
Swift简介
时间复杂度与空间复杂度
为单行查询设置JDBC Statement.setFetchSize()为1的方法指南
PPT如何开启演讲者模式?PPT开启演讲者模式的方法
ceph的部署练习
[c语言]二维数组动态分配内存
MySQL mass production of data
倾斜文档扫描与字符识别(opencv,坐标变换分析)
都在说软件测试没前途,饱和了?为何每年还会增加40万测试员?
MySQL----多表查询
移动web开发01
7.联合索引(最左前缀原则)
PHP低代码开发平台 V5.0.7新版发布
excel数字如何转换成文本?excel表格数据转换成文本的方法
Flink_CDC搭建及简单使用
These services can't ali interview?Then don't go to, the basic notification, etc
如何解决gedit 深色模式下高亮文本不可见?
化二次型为标准型
M3SDA: Moment matching for multi-source domain adaptation
canvas基础讲解加示例









