请求的棘手问题

2024-09-30 01:24:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从5个下拉列表中提取所有可能的输出组合(作为树深度),并从中生成一个通用的树数据结构

我在下拉选项中的for选项中有请求,spider只对每个for循环迭代一次

def parse(self, response):
    lastPos = response.meta['lastPos']
    ending = False
    for dropDown in reversed(response.css('select')):
        if ending == True:
            break
        dropId = dropDown.css('::attr(id)').get()
        options = dropDown.css('option::text').getall()
        for option in options:
            if option != self.root:
                self.dropDict[dropId] = option
                    request = scrapy.FormRequest(url=response.url, formdata=self.dropDict, callback=self.parse)
                    request.meta['lastPos'] = option
                    return request

蜘蛛需要遍历16个可能的序列,但我只能得到第一个序列,它总是选择第一个下拉选项。我不能寄蜘蛛的回信,它有用吗


Tags: inselfforifparseresponserequest选项

热门问题