使用request发送请求
安装:
pip install requests
request.get()
import requests
url = "http://www.baidu.com"
res.encoding = 'utf-8'
print(res.encoding)
print(res.headers)
print(res.url)
res = requests.get(url)
print(res.text)
同样也可以以加上user-agent:
import requests
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36"
}
url = "http://www.baidu.com"
res = requests.get(url, headers = header)
print(res.encoding)
print(res.headers) 。
print(res.url)
print(res.status_code)
res.encoding = 'utf-8'
print(res.text)