请求删除工具
mosquito的Python项目详细描述
蚊子
a请求混淆器和web抓取工具包
蚊子提供了一个类似于requests的api,实际上它使用
它在内部。每个http请求都会公开一些信息,例如user agent或
ip地址允许服务器识别您或您的应用程序。蚊子让我们设置
建立多个身份并将您的请求安排给他们。每个身份可以由一个整体组成
由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 \
/ \
/ \