专门做灯具海报的网站/百度权重
在写爬虫程序的过程中,如果爬取的速度过快,经常会遇到IP封禁的问题。那么为了解决这个问题,办法之一就是使用IP代理。
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
}
url = 'http://httpbin.org/ip'
proxies = {'http':'http://182.148.206.176:9999'
}
response = requests.get(url,headers=headers,proxies=proxies).text
print(response)
在设置proxies
的时候,proxies
的格式是字典的格式。前面的是协议名称,后面的格式一定要注意,否则就会代理失败。