请求删除工具

mosquito的Python项目详细描述


蚊子

a请求混淆器和web抓取工具包

蚊子提供了一个类似于requests的api,实际上它使用 它在内部。每个http请求都会公开一些信息,例如user agentip地址允许服务器识别您或您的应用程序。蚊子让我们设置 建立多个身份并将您的请求安排给他们。每个身份可以由一个整体组成 由requests支持的一组属性 session object例如:, {STR 1 } $代理/<强>或^ {STR 1 } $Cookies 。列出所有可用属性 mosquito.available_attributes()

安装

来自pypi

pip install mosquito

用法

demo/demo.py

#!/usr/bin/env python3# Standard library modules.# Third party modules.# Local modulesimportmosquitofrommosquito_testimporthttpbin# Globals and constants variables.# Register attribute callback using a decorator ...@mosquito.attribute('headers')defheaders():fornamein('linux','mac','windows'):yield{'user-agent':name}# ... or register attributes by hand.mosquito.register_attributes(delay=.0,params=[{'foo':42},{'bar':13,'baz':37}])# Let's list all available attributes.print('available:',mosquito.available_attributes())withmosquito.swarm(repeat_on=(503,),max_attempts=3)asscheduler:# Note that the swarm uses 2 sessions only, determined by the minimum length of passed# attributes which is `params` in our case.print(f'swarm uses {len(scheduler.swarm)} sessions')foriinrange(5):# `swarm wraps` requests' api and therefore supports get, post, put etc.# parameters passed directly to request method will overwrite such registered beforeresult=scheduler.get(httpbin('/user-agent'),params=dict(bar=0))print(i,result.url,result.json())# Let's provoke an error ...try:scheduler.get(httpbin('/status/404'))exceptmosquito.MosquitoErrorasmre:print(mre)# ... and another one, being more obstinate this timetry:scheduler.get(httpbin('/status/503'))exceptmosquito.MosquitoErrorasmre:print(mre)

测试

有些单元测试需要httpbin实例,默认情况下该实例为httpbin.org。 为了速度和可靠性,建议使用Docker运行自己的实例 形象。支票hub.docker.com/r/kennethreitz/httpbin 更多信息。

# run httpbin server using docker
docker run -p 8080:80 kennethreitz/httpbin

# let mosquito know its location by setting an environment variableexportHTTPBIN_BASE_URL=http://localhost:8080 

实际测试由以下人员运行:

python -m mosquito_test

反馈

如需任何反馈,请在 gitlab.com。感谢您使用

mosquito        \             /
                 \     |     /
                 /   \ | /   \
                 \    \|/    /
                  \,  o^o  ,/
                    \,/"\,/
            ,,,,----,{/X\},----,,,,
   ,,---''''      _-'{\X/}'-_      ''''---,,
 /'            ,-'/   \V/   \'-,            '\
(        ,--''/   |   (_)   |   \''--,        )
 '--,,-''    |    |   /_\   |   |     ''-,,--'
            /'    |  (_-_)  |   '\
           /     /'   \_/   '\    \
          /     /     (_)     \    \
               /       V       \
              /                 \
             /                   \             

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

推荐PyPI第三方库


热门话题
java Cassandra复制因子大于节点数   java J2EE JTA事务回滚不适用于OSE Glassfish 4.0(Build 89)   java spring安全预认证用户登录   org的java类文件。反应流。从RxJava编译示例时未找到Publisher?   java在使用dataFormat作为POJO通过Camel调用Web服务时无法设置SOAP标头   Javafx类的java静态实例   java如何防止一个部件在关闭时覆盖另一个部件的位置   sql server无法从我的java代码连接到数据库   java在JList(Swing)中显示带有的ArrayList   从Java中的CXF服务获取WSAddressing数据   使用资产文件夹进行java简单json解析(本地)   java LDAPException未绑定的无效凭据   JavaJSFspring部署到weblogic   JAVA中字符数组中的特定元素排列?   如果脚本位于不同的目录中,则ant不会使用exec标记运行Javashell脚本