mosquito
a request obfuscator and web scraping toolkit
mosquito gives you an API similar to requests and in fact uses
it internally. Each HTTP request exposes a number of information such as user agent or
IP address that allows a server to identify you or your application. mosquito lets you set
up multiple identities and schedules your requests to them. Each identity may consist of a whole
bunch of attributes that are supported by requests's
session object e.g.: headers,
proxies or cookies. To list all attributes available execute
mosquito.available_attributes()
.
Installation
from PyPI
pip install mosquito
Usage
demo/demo.py
import mosquito
from mosquito.tests import httpbin
@mosquito.attribute('headers')
def headers():
for name in ('linux', 'mac', 'windows'):
yield {'user-agent': name}
mosquito.register_attributes(delay=.0, params=[{'foo': 42}, {'bar': 13, 'baz': 37}])
print('available:', mosquito.available_attributes())
with mosquito.swarm(repeat_on=(503,), max_attempts=3) as scheduler:
print(f'swarm uses {len(scheduler.swarm)} sessions')
for i in range(5):
result = scheduler.get(httpbin('/user-agent'), params=dict(bar=0))
print(i, result.url, result.json())
try:
scheduler.get(httpbin('/status/404'))
except mosquito.MosquitoError as mre:
print(mre)
try:
scheduler.get(httpbin('/status/503'))
except mosquito.MosquitoError as mre:
print(mre)
Testing
Some unit tests require a httpbin instance which is httpbin.org by default.
For sake of speed and reliability it's recommended to run your own instance using the docker
image. Check hub.docker.com/r/kennethreitz/httpbin
for more information.
podman run -p 8080:80 kennethreitz/httpbin
export HTTPBIN_BASE_URL=http://localhost:8080
The actual test is ran by:
python -m mosquito.tests
Feedback
For feedback of any kind write an issue at
gitlab.com. Thank you for using mosquito.
mosquito \ /
\ | /
/ \ | / \
\ \|/ /
\, o^o ,/
\,/"\,/
,,,,----,{/X\},----,,,,
,,---'''' _-'{\X/}'-_ ''''---,,
/' ,-'/ \V/ \'-, '\
( ,--''/ | (_) | \''--, )
'--,,-'' | | /_\ | | ''-,,--'
/' | (_-_) | '\
/ /' \_/ '\ \
/ / (_) \ \
/ V \
/ \
/ \