reqeusts
import requests
url = 'https://www.baidu.com'
resposne = requests.get(url)
print(resposne.content) #以字節(jié)的形式返回數(shù)據(jù)
print(resposne.text) #返回已經(jīng)編碼過的字符
print(resposne.url) #返回發(fā)起請求的urll
print(resposne.cookies)# 返回一個cookie
print(resposne.encoding) #返回當前的編碼格式
print(resposne.headers) #返回一個請求頭
print(resposne.status_code) #返回一個狀態(tài)嗎
resposne.encoding='utf8' #設(shè)置編碼格式
"""
添加請求頭
"""
heads = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
# 'Referer': 'https://www.yaozh.com/login/proxy',
}
response = requests.get(url,heads)
"""
使用代理的方法發(fā)送請求
"""
proxy = {'HTTP': '9999:115.211.227.142'}
response = requests.get(self.url,proxies=proxy)