当前位置:网站首页>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'>
边栏推荐
猜你喜欢
想要写出好的测试用例,先要学会测试设计
都在说软件测试没前途,饱和了?为何每年还会增加40万测试员?
【考研词汇训练营】Day18 —— amount,max,consider,account,actual,eliminate,letter,significant,embarrass,collapse
Oblique document scanning and character recognition (opencv, coordinate transformation analysis)
TensorFlow2:概述
MySQL (2)
Android Studio 实现登录注册-源代码 (连接MySql数据库)
【无标题】多集嵌套集合使不再有MultipleBagFetchException
Face-based Common Expression Recognition (2) - Data Acquisition and Arrangement
Recommendation System - Sorting Layer: Sorting Layer Architecture [User and Item Feature Processing Steps]
随机推荐
4年测试经验去面试10分钟就被赶出来了,面试官说我还不如应届生?都这么卷吗...
360杜跃进:太空安全风险加剧,需打造一体化防御体系
并发与并行的区别
[Ask] SQL statement to calculate the sum of column 2 by deduplicating column 1?
HMS Core Discovery第16期回顾|与虎墩一起,玩转AI新“声”态
Recommendation system: evaluation index [offline evaluation index: RMSE (root mean square error), AUC, precision, recall, F1] [online evaluation: A/B test] [generally required response time <0.5s]
MySQL_关于JSON数据的查询
@WebServlet注解(Servlet注解)
MySQL kills 10 questions, how many questions can you stick to?
Swift简介
为单行查询设置JDBC Statement.setFetchSize()为1的方法指南
MySQL8重置root账户密码图文教程
CDH集群spark-shell执行过程分析
肖特基二极管厂家ASEMI带你认识电路中的三大重要元器件
基于人脸的常见表情识别(2)——数据获取与整理
多线程获取官方汇率
推荐系统-模型:FNN模型(FM+MLP=FNN)
【PM专用】快速统计团队还有谁没有登记上报信息,快速筛选出属于自己项目组的成员,未完成XXX工作事项的名单
Can't find the distributed lock of Redisson?
7.联合索引(最左前缀原则)