pubproxy.com的一个易于使用的python包装器
pubproxp的Python项目详细描述
pubproxpy
一个易于使用的python包装器,用于pubproxy的公共代理api。
安装
使用标准的python包管理器安装pubproxpy包,例如
$ pip install pubproxpy
一如既往,建议您安装到虚拟环境中
无钥匙API限制
API每日限值
在没有API密钥的情况下,PubPosivAPI将用户限制为5个代理请求和50个请求。每个请求的最大代理总是用来最小化速率限制,同时在请求限制内获得最多代理可能意味着您不需要API密钥就可以每天获得250个代理。
API速率限制
如果没有api密钥,pubproxy会将用户限制为每秒一个请求,因此ProxyFetcher
将尝试确保在没有api密钥的情况下,每秒最多只能完成一个请求。这是在ProxyFetcher
s之间同步的,但这不是线程安全的,因此如果没有api密钥,请确保所有ProxyFetcher
s都在一个程序的一个线程上。速率限制相当严重,因此一旦被命中,api似乎会拒绝数分钟/小时的请求。
快速启动示例
frompubproxpyimportProxyFetcher# ProxyFetcher for proxies that use the socks5 protocol, are located in# the US or Canada and support POST requestssocks_pf=ProxyFetcher(protocol="socks5",countries=["US","CA"],post=True)# ProxyFetcher for proxies that support https, are elite anonymity level,# and connected in 15 seconds or lesshttp_pf=ProxyFetcher(protocol="http",https=True,level="elite",time_to_connect=15)# Get one socks proxy, followed by 10 https proxies# NOTE: even though there are multiple `ProxyFetcher`s the delays are# coordinated to prevent rate limitingsocks_proxy=socks_pf.get_proxy()# Returns a single proxy as a stringhttps_proxy=http_pf.get_proxies(10)# Returns a list of proxies as strings# Do something with the proxies, like spawn worker threads that use them
文件
获取代理是由^ {CD1>}类处理的。有几个参数可以在初始化时传递,以将代理缩小到合适的类型。在那里,您可以直接调用,以收到一个代理的形式,例如,或接收到一个列表。有一个内部黑名单来确保同一个代理IP和端口组合不会被任何ProxyFetcher
多次使用,除非exclude_used
是False
。
ProxyFetcher
参数
由于api几乎不检查任何内容的正确性,因此我们尽最大努力确保没有任何错误。据我所知,唯一没有检查的是countries
或not_countries
实际上使用了正确的代码。
Parameter | Type | Description |
---|---|---|
^{ | ^{ | If the ^{ |
^{ | ^{ | API key for a paid account, you can also set ^{ |
^{ | ^{ | [Options: anonymous, elite] Proxy anonymity level |
^{ | ^{ | [Options: http, socks4, socks5] Desired communication protocol |
^{ | ^{ | Locations of the proxy using the ISO-3166 alpha-2 country code, Incompatible with ^{ |
^{ | ^{ | Blacklist locations of the proxy using the ISO-3166 alpha-2 country code, Incompatible with ^{ |
^{ | ^{ | [Bounds: 1-1000] Minutes since the proxy was checked |
^{ | ^{ | Proxies using a specific port |
^{ | ^{ | [Bounds: 1-60] How many seconds it took for the proxy to connect |
^{ | ^{ | Supports requests with cookies |
^{ | ^{ | Can connect to Google |
^{ | ^{ | Supports HTTPS requests |
^{ | ^{ | Supports POST requests |
^{ | ^{ | Supports referer requests |
^{ | ^{ | Supports forwarding user-agents |
ProxyFetcher
方法
保持简单(愚蠢),所以只要get_proxy()
和get_proxies(amount)
。
Method | Returns |
---|---|
^{ | Single proxy as a string, format ^{ |
^{ | List of ^{ |
异常
所有异常都在errors.py
中定义
Exception | Description |
---|---|
^{ | Base exception that all other pubproxpy errors inherit from |
^{ | Error raised when the API gives an incorrect API Key response |
^{ | Error raised when the API gives a rate-limiting response (more than 1 request per second) |
^{ | Error raised when the API gives the daily request limit response |