"""
请求:
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)
爬虫 requests请求库使用
最新推荐文章于 2024-10-05 08:57:27 发布