此为历史版本和 IPFS 入口查阅区,回到作品页
shixiaolong0
IPFS 指纹 这是什么

作品指纹

Scrapy 解析方法中的**kwargs具体怎么用

shixiaolong0
·
·

示例:


import scrapy

class MySpider(scrapy.Spider):
    name = 'myspider'
    start_urls = ['http://www.example.com']

    def start_requests(self):
        for url in self.start_urls:
            headers = {'User-Agent': 'Mozilla/5.0'}
            yield scrapy.Request(url, callback=self.parse, headers=headers)

    def parse(self, response, **kwargs):
        headers = kwargs.get('headers')
        self.logger.info(f'User-Agent = {headers.get("User-Agent")}')
        # your parsing logic here

CC BY-NC-ND 4.0 授权