如何在Scrapy中使用不同参数多次访问URL?

2 投票
1 回答
1056 浏览
提问于 2025-04-18 13:25

我有一个解析函数,如下所示:

def parse(self,response):
    a = list(map(chr, range(97,123)))
    for i in a:
        yield FormRequest.from_response(
            response,
            formdata = {'posted':'posted', 'LastName':i, 'distance':'0', 'current_page':'2'},
            callback = self.after
        )

在这里,我向同一个网址发送请求,但每次使用不同的姓氏参数,如上所示。不过,它并没有对我所有的请求都返回响应。相反,它只获取了字母'Q'的结果。怎么才能让它每次都用不同的参数访问同一个网址呢?

1 个回答

1

你需要在你的 FormRequest 上设置 dont_filter = True

yield FormRequest.from_response(
    response,
    formdata = {'posted':'posted', 'LastName':i, 'distance':'0', 'current_page':'2'},
    callback = self.after,
    dont_filter=True
)

想了解更多信息,可以查看这个链接:http://doc.scrapy.org/en/latest/topics/request-response.html

撰写回答