from scrapy.settings import Settings custom_settings = Settings({ 'USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' }) class MySpider(scrapy.Spider): name = 'myspider' custom_settings = custom_settings ...
from scrapy.settings import Settings from myproject.middleware import MyMiddleware custom_settings = Settings({ 'DOWNLOADER_MIDDLEWARES': { 'myproject.middleware.MyMiddleware': 543, } }) class MySpider(scrapy.Spider): name = 'myspider' custom_settings = custom_settings ...In this example, a custom middleware class named `MyMiddleware` is defined in the `myproject.middleware` module, and added to the `DOWNLOADER_MIDDLEWARES` setting with a priority of 543. Package Library: Scrapy.