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为什么我必须强制转换这个泛型类型?   如何使用Java查找、读取和显示文本文件中的行   java URL在标签后被剪切   java加速计+按钮   java J2ME应用程序选择性地在某些手机上工作   java如何在自定义对话框内的webview上加载完网页?   java IntelliJ结构化搜索和替换问题   java从现有项目创建新的本地回购   java如何在netbeans IDE上启用只读代码?   java表达式的类型必须是数组类型,但解析为双精度   java Apache Camel:bean组件将sql结果集转换为csv:处理空值   java如何分配多个字段作为实体的主键(使用JPA)   java使用JSON从HttpClient请求解析JSON。组织分析器   java将输入转换为多个Int/Var   sqljava。lang.NullPointerException:无法对null对象调用方法addURL()   java Spring SecurityConfig单元测试,用于忽略特定URL上的Web安全性   一个或多个条件的java设计模式   java在本地主机上运行web应用程序   java如何在布局之间滑动时打开音频文件?