使用和urllib很相似,直接看代码
import requests
# 代理以字典形式写出来
proxy = {
'http': '219.149.59.250:9797',
'https': '219.149.59.250:9797'
}
data = {
'wd': 'ip'
}
url = 'http://www.baidu.com/s?'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537'
}
r = requests.get(url=url, headers=headers, params=data, proxies=proxy)
with open('proxy.html', 'w', encoding='utf-8') as fp:
fp.write(r.text)