开源项目IPProxys的使用

开源项目IPProxys的使用
前几天看了一下github上,IPProxys开源项目快100star了,看来大家对这个项目还是比较感兴趣的。最近一直没更新文章,主要是忙实验室的工作和写一个之前给大家提到新的开源项目,我将它命名为PowerProxy,写的过程中遇到了很多问题,算是一个不错的学习经历,对sock5协议,windows内核有了一定的理解。开源的日期还没确定,需要将一些关键问题解决,大家敬请期待。(我的新书《Python爬虫开发与项目实战》发布了,大家在这里可以看到样章

看到大家对IPProxys项目挺感兴趣,下面就介绍一下它的使用方式。

IPProxys使用

项目依赖

ubuntu,debian下

  • 安装sqlite数据库(一般系统内置):
    apt-get install sqlite3
  • 安装requests库:
    pip install requests
  • 安装lxml:
    apt-get install python-lxml
  • 安装gevent库:
    pip install gevent
(有时候使用的gevent版本过低会出现自动退出情况,请使用pip install gevent –upgrade更新)

windows下

  • 下载sqlite,路径添加到环境变量
  • 安装requests库:
    pip install requests
  • 安装lxml:
    pip install lxml或者下载lxml windows版
  • 安装gevent库:
    pip install gevent
(有时候使用的gevent版本过低会出现自动退出情况,请使用pip install gevent –upgrade更新)

如何使用

将项目目录clone到当前文件夹

$ git clone https://github.com/qiyeboy/IPProxys

切换工程目录

$ cd IPProxys

运行脚本

python IPProxys.py

API 使用方法

模式

GET /

参数

NameTypeDescription
typesint0: 高匿代理, 1 透明
protocolint0: http, 1 https
countint数量
countrystr国家
areastr地区

例子

IPProxys默认端口为8000
如果是在本机上测试:

1.获取5个ip地址在中国的高匿代理:http://127.0.0.1:8000/?types=0&count=5&country=中国

2.响应为JSON格式,按照响应速度由高到低,返回数据:

[{“ip”: “220.160.22.115”, “port”: 80}, {“ip”: “183.129.151.130”, “port”: 80}, {“ip”: “59.52.243.88”, “port”: 80}, {“ip”: “112.228.35.24”, “port”: 8888}, {“ip”: “106.75.176.4”, “port”: 80}]

import requests
import json
r = requests.get('http://127.0.0.1:8000/?types=0&count=5&country=中国')
ip_ports = json.loads(r.text)
print ip_ports
ip = ip_ports[0]['ip']
port = ip_ports[0]['port']
proxies={
    'http':'http://%s:%s'%(ip,port),
    'https':'http://%s:%s'%(ip,port)
}
r = requests.get('http://ip.chinaz.com/',proxies=proxies)
r.encoding='utf-8'
print r.text

TODO

1.添加对Python3.x的支持

2.可自主选择添加squid反向代理服务器,简化爬虫配置

3.重构HTTP API接口

4.增加更多代理网站和数据库适配

    原文作者:qiye
    原文地址: https://www.jianshu.com/p/f7464039735b
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞