欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

requests_xcdl(requests_西刺代理)

程序员文章站 2022-07-13 13:00:13
...
import requests
url = 'http://www.xicidaili.com'
# <!-- 添加proxy -->
proxy = {
    'http':'http://root:[email protected]:8118'
}
# <!-- 添加 headers -->
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
# <!-- 调用requests,得到response -->
response = requests.get(url,headers=headers,proxies=proxy)
print(response.text)

with open('xicidaili.html','wb') as f:
    f.write(response.content)