爬虫 requests请求库使用

"""
请求:
urllib: 基础(不需要安装,不太方便)
from urllib import request
requests: 高级(需要自己安装,使用方便)
终端、terminal
(venv) PS E:\python2407>
从国外镜像下载慢 所有使用清华镜像源
pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple/

处理:
保存:
"""

# from urllib import request
# import json
#
# res = request.urlopen("https://pvp.qq.com/web201605/js/herolist.json")
# content = res.read().decode()
# datas = json.loads(content)
# print(type(datas))


# import requests
# import json
# res = requests.get("https://pvp.qq.com/web201605/js/herolist.json")
#
# # content = res.text
# # datas = json.loads(content)
#
# datas = res.json()
# print(type(datas))

# # 使用content 获取二进制信息
# import requests
# res = requests.get("https://files.jb51.net/image/glob1pmart.png")
# with open("./picture/mart.png", "wb") as f:
# # 处理图片等二进制信息
# f.write(res.content)


# 自己手动解码
# import requests
# res = requests.get("https://www.jb51.net/python/325383w1r.htm")
# # 200 代表成功
# print(res.status_code)
# # 因为请求下来的信息 需要解码 所有只能使用content属性 然后结合decode手动解密
# print(res.content.decode())



# requests 请求数据如何解析
# 第一种方式 直接使用json()函数 前提是服务器返回数据能使用json
# 第二种方式 直接使用text属性 前提是服务器返回数据不需要解码
# 第三种方式 使用content属性 适合请求二进制,或者文本信息(需要自己手动解码)




# import requests
#
# res = requests.get("https://baijiahao.baidu.com/s?id=1809169150957547304")
#
# print(res.text)
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农NoError

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值