一个简单的工具来代理ip

华盟原创文章投稿奖励计划

自动草稿

IP代理
中文版
一个简单的工具来代理ip。
要求
Python 2.7
Virtualenv(可选)
点子(可选)
您可以virtualenv用来建立新的python虚拟环境,并pip安装所有依赖项。但是,您可以使用任何其他喜欢的工具。
用法
建立环境
为这个项目构建一个新的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 debug
Output(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。
数据
http://www.cz88.net/proxy
http://www.kuaidaili.com
http://www.xicidaili.com
http://cn-proxy.com
http://www.66ip.cn
执照
只是享受它。
【文章来源】:

https://github.com/jiehua233/ipproxy

本文原创,作者:congtou,其版权均为华盟网所有。如需转载,请注明出处:https://www.77169.net/download/263145.html

发表评论