您的位置:首页 > 代理IP资讯
发布时间:2021-03-12 15:55:39
Python简单代理ip工具virtualenv

一.要求

Python 2.7

Virtualenv(可选)

点子(可选)

您可以virtualenv用来建立新的python虚拟环境,并pip安装所有依赖项。


但是,您可以使用任何其他喜欢的工具。py的代理ip工具




二.用法

建立环境

为这个项目构建一个新的virtualenv,在shell中运行:


$ virtualenv ~/virtualenvs/ipproxy

$ source ~/virtualenvs/ipproxy/bin/activate 

(ipproxy)$ pip install -r requirements.txt 


抓取可能的代理IP

然后从一些预定义的网站中搜寻所有可能的代理IP:

(ipproxy)$ python crawl.py 



等待一会儿,只需一杯咖啡(可能会更长一些,这完全取决于您的网络)


您将在data目录中得到结果:


all.csv

china.csv

foreign.csv

high_anonymous.csv

low_anonymous.csv

non_anonymous.csv



每个CSV文件包含四列:ip,port,anonymous,info。




好像:


ip,port,anonymous,info

110.73.0.125,8123,3,中国-广西-防城港

207.226.142.113,3128,3,中国-香港

......


对于anonymous列,这意味着:


0:未知

1:无

2:低

3:高




检查可用的代理IP


(ipproxy)$ python check.py --help


usage: check.py [-h] [--target TARGET] [--timeout TIMEOUT] [--worker WORKER]


               [--thread THREAD] [--loglevel LOGLEVEL]


               input



positional arguments:


 input                the input proxy ip list, in csv format(supprot gz)



optional arguments:


 -h, --help          show this help message and exit


 --target TARGET      target uri to validate proxy ip, default:


                      http://www.baidu.com


 --timeout TIMEOUT    timeout of validating each ip, default: 15s


 --worker WORKER      run with multi workers, default: CPU cores


 --thread THREAD      run with multi thread in each worker, default: 100


 --loglevel LOGLEVEL  set log level, e.g. debug, info, warn, error; default:                       info


因此,将上述csv作为输入,您可以运行:



(ipproxy)$ python check.py data/high_anonymous.csv您还可以指定其他一些参数:



(ipproxy)$ python main.py input.csv --target http://www.google.com.hk --timeout 10 --worker 4 --thread 200 --loglevel debugOutput(data/proxyip.csv)与输入相似,多一个col speed(越小越好):



ip,port,anonymous,info,speed


110.84.128.143,3128,1,中国-福建-福州,0.10766482353210449


58.247.125.205,10032,3,中国-上海-上海,0.5216059684753418


......




三.最后的最后

例:看一看example.py。


数据源:

https://www.feizhuip.com/News-newsList-catid-8.html

http://h.feizhuip.com/Index-getapi.html



上一篇 下一篇