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密钥的情况下,每秒最多只能完成一个请求。这是在ProxyFetchers之间同步的,但这不是线程安全的,因此如果没有api密钥,请确保所有ProxyFetchers都在一个程序的一个线程上。速率限制相当严重,因此一旦被命中,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_usedFalse

ProxyFetcher参数

由于api几乎不检查任何内容的正确性,因此我们尽最大努力确保没有任何错误。据我所知,唯一没有检查的是countriesnot_countries实际上使用了正确的代码。

ParameterTypeDescription
^{}^{}If the ^{} should prevent re-returning proxies
^{}^{}API key for a paid account, you can also set ^{} to pass your key, passing the ^{} parameter will override the env-var
^{}^{}[Options: anonymous, elite] Proxy anonymity level
^{}^{}[Options: http, socks4, socks5] Desired communication protocol
^{}^{} or ^{}Locations of the proxy using the ISO-3166 alpha-2 country code, Incompatible with ^{}
^{}^{} or ^{}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)

MethodReturns
^{}Single proxy as a string, format ^{}
^{}List of ^{} proxies, same format as above

异常

所有异常都在errors.py中定义

ExceptionDescription
^{}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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java:字符串。RTL设备语言用标志“+”格式化,数字后加符号   java GAE作为桌面应用程序(Swing)的服务提供商   java将InputStream转换为FileInputStream不适用于Apache POI   java外部Voronoi库“网格”:什么是草图和处理?   重载重写的泛型方法java   java显示组织上设置的错误。springframework。验证。jsp中的错误对象   java一些Spring模型属性没有显示在我的JSP中   java无法编译Guava 23的SimpleTimeLimiter示例   java如何更改JTree中的“根”目录名?   java如何在安卓中对相对布局产生连锁反应?   java错误:org。冬眠例外SQLGrammarException:无法提取结果集,dateAccessed是未知列   如何使用java监听JSON文件更新   由抽象封闭类创建的匿名内部类能否通过反射确定实现类?