Skip to main content
# getproxy

[![Build Status](https://travis-ci.org/fate0/getproxy.svg?branch=master)](https://travis-ci.org/fate0/getproxy)
[![Updates](https://pyup.io/repos/github/fate0/getproxy/shield.svg)](https://pyup.io/repos/github/fate0/getproxy/)
[![PyPI](https://img.shields.io/pypi/v/getproxy.svg)](https://pypi.python.org/pypi/getproxy)
[![PyPI](https://img.shields.io/pypi/pyversions/getproxy.svg)](https://pypi.python.org/pypi/getproxy)

getproxy 是一个抓取发放代理网站,获取 http/https 代理的程序,
每 15 min 会更新数据至 [fate0/proxylist](https://github.com/fate0/proxylist)


## 1. 安装

```
pip install -U getproxy
```

## 2. 使用

### 帮助信息
```
➜ ~ getproxy --help
Usage: getproxy [OPTIONS]

Options:
--in-proxy TEXT Input proxy file
--out-proxy TEXT Output proxy file
--help Show this message and exit.
```

* `--in-proxy` 可选参数,待验证的 proxies 列表文件
* `--out-proxy` 可选参数,输出已验证的 proxies 列表文件,如果为空,则直接输出到终端

`--in-proxy` 文件格式和 `--out-proxy` 文件格式一致

### 使用例子

```
(test2.7) ➜ ~ getproxy
INFO:getproxy.getproxy:[*] Init
INFO:getproxy.getproxy:[*] Current Ip Address: 1.1.1.1
INFO:getproxy.getproxy:[*] Load input proxies
INFO:getproxy.getproxy:[*] Validate input proxies
INFO:getproxy.getproxy:[*] Load plugins
INFO:getproxy.getproxy:[*] Grab proxies
INFO:getproxy.getproxy:[*] Validate web proxies
INFO:getproxy.getproxy:[*] Check 6666 proxies, Got 666 valid proxies

...
```


## 3. 输入/返回格式

每一行结果都是一个 json 字符串,格式如下:
```json
{
"type": "http",
"host": "1.1.1.1",
"port": 8080,
"anonymity": "transparent",
"country": "CN",
"response_time": 3.14,
"from": "txt"
}
```

| 属性   | 类型   | 描述   | 可选值   |
|------- |--------|-------- |----------|
| type | str   | proxy 类型 | `http`, `https`|
| host         | str   | proxy 地址 | |
| port         | int   | 端口 | |
| anonymity     | str   | 匿名性 | `transparent`, `anonymous`, `high_anonymous` |
| country | str | proxy 国家 | |
| response_time | float | 响应时间 | |
| from         | str   | 来源 | |


## 4. Plugin 相关

### Plugin 代码格式

``` python

class Proxy(object):
def __init__(self):
self.result = []
self.proxies = []

def start(self):
pass
```

### Plugin 返回结果

```
{
"host": "1.1.1.1",
"port": 8080,
"from": "plugin name"
}
```

### Plugin 小提示

* 不要在 plugin 内使用多线程、gevent 等方法
* 如果目标网站存在分页,请在获取每页内容之后,自行添加 delay
* 如果目标网站存在分页,请在获取每页结果之后,及时放入 `self.result` 中
* 如果被目标网站 ban 了,可以利用已经验证的 proxies (也就是 `self.proxies`)

## 5. 第三方程序调用

直接运行 `getproxy` 等同于执行下面程序:

``` python
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from getproxy import GetProxy

g = GetProxy()

# 1. 初始化,必须步骤
g.init()

# 2. 加载 input proxies 列表
g.load_input_proxies()

# 3. 验证 input proxies 列表
g.validate_input_proxies()

# 4. 加载 plugin
g.load_plugins()

# 5. 抓取 web proxies 列表
g.grab_web_proxies()

# 6. 验证 web proxies 列表
g.validate_web_proxies()

# 7. 保存当前所有已验证的 proxies 列表
g.save_proxies()

```

如果只想验证 proxies 列表,并不需要抓取别人的 proxies,则可以:

``` python
g.init()
g.load_input_proxies()
g.validate_input_proxies()

print(g.valid_proxies)
```

如果当前程序不需要输出 proxies 列表,而是在程序中直接使用,则可以:

``` python
g.init()
g.load_plugins()
g.grab_web_proxies()
g.validate_web_proxies()

print(g.valid_proxies)
```

## 6. Q & A

* 为什么不使用 xxx 数据库?

数据量并不大,就算用文本格式全读进内存,也占用不了多少内存,就算真的需要存储至数据库,自己再多写几行代码就搞定。
另外使用文本格式还有另外一个好处是可以创建这个项目 [fate0/proxylist](https://github.com/fate0/proxylist)

* 和 xxx 有什么区别?

简单、方便、快捷,除了 Python 环境,其他都不用设置。

* 报错啦,怎么办?

仔细看看错误信息,是不是一些 plugin 报错误,而且错误都是和网络相关的?
如果是的话,可能这些 plugin 访问的网站由于众所周知的原因被 block 了。
如果不是,赶紧提 Issue。

* 还继续添加新的 plugin 吗?

主要看这个项目 [fate0/proxylist](https://github.com/fate0/proxylist) 中的 `proxy.list` 数量,
如果 `proxy.list` 行数接近 5000 个,那就不再继续添加新的 plugin,防止 travis 15min 内不结束。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

getproxy-0.2.3.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

getproxy-0.2.3-py2.py3-none-any.whl (1.4 MB view details)

Uploaded Python 2Python 3

File details

Details for the file getproxy-0.2.3.tar.gz.

File metadata

  • Download URL: getproxy-0.2.3.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for getproxy-0.2.3.tar.gz
Algorithm Hash digest
SHA256 552e6b4db37abe97914ef9eb0b88b50f6714054d72ddb4df191f284baeb05ae5
MD5 aaa68f475ef980be5a0504a977b71fb2
BLAKE2b-256 ea9939d8a796023b9a81754841c23e3e7dfbf6192be2002226d78cee5dd736ca

See more details on using hashes here.

File details

Details for the file getproxy-0.2.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for getproxy-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e6e9ddc22819ecee1602ce36c7a3fd42b9be0c4940c795e1ef000e25b55228f4
MD5 997d57b68bcde4b6c3b2e52fac935837
BLAKE2b-256 bc242aa27483d9e979e5f0b23804d60a6ce9e630424af0431396fcf11edf72a7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page