标签:ext 实例 agent loading 错误 encoding exce coding bsp
1、获取URL对应的资源
get、head
2、实例
try:
url = ‘https://www.baidu.com/s?‘
kv = {‘wd‘: ‘python‘}
hd = {‘user-agent‘: ‘Chrome/10‘}
r = requests.get(url, params=kv, headers=hd, timeout=10)
r.raise_for_status()
# 用r.request查看请求信息
print(r.request.url)
print(r.url)
print(r.request.headers)
print(r.headers)
print(r.encoding)
print(r.apparent_encoding)
r.encoding = r.apparent_encoding
print(r.text[:1000])
url = ‘https://www.baidu.com‘
r = requests.head(url)
print(r.headers)
print(r.text)
except:
print(‘请求错误‘)
标签:ext 实例 agent loading 错误 encoding exce coding bsp
原文地址:https://www.cnblogs.com/liujianing/p/13178211.html