scrapy随机切换user-agent

使用github的 scrapy-fake-useragent 不用自己改源码继承自带的userAgent中间件  只需要安装后增加配置即可

https://github.com/alecxe/scrapy-fake-useragent

 

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,
}
posted @ 2019-11-11 10:38  brady-wang  阅读(376)  评论(0编辑  收藏  举报