Python网络库requests使用代理

有时候我们在使用python爬虫的时候对某些特殊URL地址访问时需要通过代理的方式,使用requests库可以方便的通过参数支持:

import requests

proxies = {'http': 'http://gfw.xxx.com:8118', 'https': 'http://gfw.xxx.com:8118'}

content = requests.get("https://play.google.com/store", proxies=proxies)
print content

content = requests.get("http://www.google.com", proxies=proxies)
print content

 

设置代理方便多了。

猜你喜欢

转载自hzy3774.iteye.com/blog/2370636