当前位置:网站首页>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'>
边栏推荐
- PHP低代码开发引擎—表单设计
- [c语言]二维数组动态分配内存
- OSS简单上传图片
- 湖仓一体电商项目(四):项目数据种类与采集
- Face-based Common Expression Recognition (2) - Data Acquisition and Arrangement
- 基于人脸的常见表情识别——模型搭建、训练与测试
- 推荐系统:实时性【特征实时性:客户端实时特征(秒级,实时)、流处理平台(分钟级,近实时)、分布式批处理平台(小时/天级,非实时)】【模型实时性:在线学习、增量更新、全量更新】
- Android studio连接MySQL并完成简单的登录注册功能
- 2022年SQL经典面试题总结(带解析)
- excel数字下拉递增怎么设置?
猜你喜欢
Mysql索引特性(重要)
基于Apache Doris的湖仓分析
MySQL database --- Addition, deletion, modification and query of MySQL tables (advanced)
PPT如何开启演讲者模式?PPT开启演讲者模式的方法
Office365无法打开word文档怎么办?Office365无法打开word文档的解决方法
我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你
普通的int main(){}没有写return 0;会怎么样?
肖特基二极管厂家ASEMI带你认识电路中的三大重要元器件
MySql密码
vlookup函数匹配不出来的原因及解决方法
随机推荐
如何优化OpenSumi终端性能?
Mysql8创建用户以及赋权操作
Multi-threaded mutex application RAII mechanism
[NISACTF 2022]下
WPS表格怎么自动1234排下去?wps表格怎么自动生成序号?
MySQL----多表查询
线性结构:栈和队列
MySQL的主从复制
mysql 递归函数with recursive的用法
推荐系统-排序层-模型(一):Embedding + MLP(多层感知机)模型【Deep Crossing模型:经典的Embedding+MLP模型结构】
[PM only] Quickly count who else in the team has not registered and reported information, and quickly screen out the members of their own project team who have not completed the list of XXX work items
Weak Banks to data conversion ability?Matt software help solve bank dilemma
[Ask] SQL statement to calculate the sum of column 2 by deduplicating column 1?
PPT如何开启演讲者模式?PPT开启演讲者模式的方法
bebel系列- 插件开发
SQLyog注释 添加 撤销 快捷键
Face-based Common Expression Recognition (2) - Data Acquisition and Arrangement
MySql密码
想要写出好的测试用例,先要学会测试设计
线性结构:顺序表和链表