python requests指定出口ip的例子

爱蒂网

python requests指定出口ip的例子

2020-03-15 20:31:32 分类 / 代码专栏 来源 / 互联网

今天小编就为大家分享一篇python requests指定出口ip的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

爬虫需要,一个机器多个口,一个口多个ip,为轮询这些ip

demo

#coding=utf-8
import requests,sys,socket
from requests_toolbelt.adapters import source
reload(sys)
sys.setdefaultencoding('utf-8')


s = requests.Session()
new_source = source.SourceAddressAdapter('192.168.4.2')
s.mount('http://', new_source)
s.mount('https://', new_source)
print s.get('http://xxx.xxx.xxx.xxx:8091/')

需要安装第三方模块requests_toolbelt

pip install requests_toolbelt

Done

以上这篇python requests指定出口ip的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持爱蒂网。

猜你喜欢