requests库入门-3-requests小demo

1.用Requests发送百度请求

新建一个requests_test.py文件,输入如下内容。

import requests

#请求百度网页
response = requests.get("https://www.baidu.com", data=None,timeout=10)
print(response.headers)

#打印内容如下

{'Cache-Control': 'private, no-cache, no-store, proxy-revalidate, no-transform',
'Connection': 'Keep-Alive',
'Content-Encoding': 'gzip',
'Content-Type': 'text/html',
'Date': 'Wed, 23 Aug 2017 14:51:05 GMT',
'Last-Modified': 'Mon, 23 Jan 2017 13:23:51 GMT',
'Pragma': 'no-cache',
'Server': 'bfe/1.0.8.18',
'Set-Cookie': 'BDORZ=27315; max-age=86400; domain=.baidu.com; path=/',
'Transfer-Encoding': 'chunked'
}

原文地址:https://www.cnblogs.com/weihanhan/p/14669904.html