请求删除工具

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第三方库


热门话题
datetime如何使用JodaTime在Java中设置时间属性   java固定算法的性能时间   java如何从JMenu中获取所选项以更改文本区域的文本颜色?   java配置单元UDF传递数组<string>作为参数   javaapachebeam和BigQuery   java与PrintWriter之间的差异。printf和PrintWriter。格式方法   继承如何处理按Java版本更改的导入,以及在多个版本上编译   xml java。lang.noClassDefFoundant生成错误   java如何使用包含映射的JSON发送POST请求?   java如何在任何应用程序的JAR文件中绑定MySql数据库?   Java脚本解释器   sslhttpclientjava。网SocketException:未实现未连接的socket   java如何为Android应用程序创建类似于Cron作业的东西   java JButton+radiobox+复选框   java内存管理将文件写入内存   java这是计算对象实例的有效方法吗?   用于死锁情况的java代码?   JavaSpring容器作为新实体插入,而不是存储在表中