python requests指定出口ip的例子

yipeiwu_com6年前Python基础

爬虫需要,一个机器多个口,一个口多个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的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python中的zip函数使用示例

zip函数接受任意多个(包括0个和1个)序列作为参数,返回一个tuple列表。具体意思不好用文字来表述,直接看示例: 1.示例1: 复制代码 代码如下: x = [1, 2, 3] y...

python实现生成字符串大小写字母和数字的各种组合

1 输出大写字母、小写字母、大小写字母、数字、大小写字母和数字 1.1输出小写:找到小写a(97)到z(122)的的ASCII码,然后转义为字母 lower = "" for i i...

Django URL传递参数的方法总结

1 无参数情况 配置URL及其视图如下: (r'^hello/$', hello) def hello(request): return HttpResponse("Hell...

Python读写文件模式和文件对象方法实例详解

Python读写文件模式和文件对象方法实例详解

本文实例讲述了Python读写文件模式和文件对象方法。分享给大家供大家参考,具体如下: 一. 读写文件模式 利用open() 读写文件时,将会返回一个 file 对象,其基本语法格式如...

python的Tqdm模块的使用

Tqdm 是一个快速,可扩展的Python进度条,可以在 Python 长循环中添加一个进度提示信息,用户只需要封装任意的迭代器 tqdm(iterator)。 我的系统是window...