Use a random User-Agent provided by fake-useragent for every request
Project description
scrapy-fake-useragent
Random User-Agent middleware based on fake-useragent. It picks up User-Agent strings based on usage statistics from a real world database.
Installation
The simplest way is to install it via pip:
pip install scrapy-fake-useragent
Configuration
Turn off the built-in UserAgentMiddleware and add RandomUserAgentMiddleware.
In Scrapy >=1.0:
DOWNLOADER_MIDDLEWARES = {
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
'scrapy_fake_useragent.middleware.RandomUserAgentMiddleware': 400,
}
In Scrapy <1.0:
DOWNLOADER_MIDDLEWARES = {
'scrapy.contrib.downloadermiddleware.useragent.UserAgentMiddleware': None,
'scrapy_fake_useragent.middleware.RandomUserAgentMiddleware': 400,
}
Configuring User-Agent type
There’s a configuration parameter RANDOM_UA_TYPE defaulting to random which is passed verbatim to the fake-user-agent. Therefore you can set it to say firefox to mimic only firefox browsers. Most useful though would be to use desktop or mobile values to send desktop or mobile strings respectively.
Usage with scrapy-proxies
To use with middlewares of random proxy such as scrapy-proxies, you need:
set RANDOM_UA_PER_PROXY to True to allow switch per proxy
set priority of RandomUserAgentMiddleware to be greater than scrapy-proxies, so that proxy is set before handle UA
Configuring Fake-UserAgent fallback
There’s a configuration parameter FAKEUSERAGENT_FALLBACK defaulting to None. You can set it to a string value, for example Mozilla or Your favorite browser, this configuration can completely disable any annoying exception.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for scrapy-fake-useragent-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf004a651545585f2f05f0bd66cfe8c9df35778babf53bdfd856092d8b3b4068 |
|
MD5 | 8200cad1a93e9b68311d3f1252b2c168 |
|
BLAKE2b-256 | bd662daceedbf66a879e799a7405988842f917d4f8655475b707b9944304e103 |
Hashes for scrapy_fake_useragent-1.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4898772a7c5e6f7c58269c895ade39aab87038d2efea73fbe15a4aab1335f0b6 |
|
MD5 | 61d223b4a2d67ba4450bae720cf6b4f1 |
|
BLAKE2b-256 | 0d1bc9e5f1917c87a09787271933dcd4bface93ee60248a6a85cc98f2fd58e2c |