当前位置:网站首页>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'>
边栏推荐
猜你喜欢

M3SDA: Moment matching for multi-source domain adaptation

【视频】极值理论EVT与R语言应用:GPD模型火灾损失分布分析

并发与并行的区别

MYSQL 唯一约束

Network layer protocol------IP protocol

Android Studio 实现登录注册-源代码 (连接MySql数据库)

6.3有定型性 第七章

是对称矩阵的对角化

excel数字下拉递增怎么设置?
![[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](/img/74/94c254b7694a77d635f5f538a72fe0.png)
[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
随机推荐
HMS Core Discovery第16期回顾|与虎墩一起,玩转AI新“声”态
MySQL mass production of data
无法正常访问服务器
vlookup函数匹配不出来只显示公式的解决方法
MySQL_关于JSON数据的查询
Mysql 回表
Android Studio 实现登录注册-源代码 (连接MySql数据库)
【考研词汇训练营】Day18 —— amount,max,consider,account,actual,eliminate,letter,significant,embarrass,collapse
MySQL----多表查询
360杜跃进:太空安全风险加剧,需打造一体化防御体系
Recommendation system-model: FNN model (FM+MLP=FNN)
利用go制作微信机器人
4年测试经验去面试10分钟就被赶出来了,面试官说我还不如应届生?都这么卷吗...
ELK log analysis system
MySQL ODBC驱动简介
@RequestParam使用
Activiti 工作流引擎 详解
Difference Between Concurrency and Parallelism
Common Expression Recognition Based on Face (1) - Basic Knowledge of Deep Learning
KEIL problem: [keil Error: failed to execute 'C:\Keil\ARM\ARMCC']