【问题标题】:Scrapy not sending post requestScrapy不发送post请求
【发布时间】:2020-11-29 16:39:46
【问题描述】:

我试图向一个 URL 发出 post 请求,但 scrapy 没有发送 post 请求。我没有得到正确的回应。

下面是我的代码。

import scrapy

class MainSpider(scrapy.Spider):
    name = 'main'
    directory = 'https://www.constructionenquirer.com/directory'
    start_urls = [directory]

    def parse(self, response):
        sectors = response.xpath('(//select[@name="sector"]/option)[position()>1]')
        for sector in sectors:
            vals = sector.xpath('.//@value').get()

            data = {
                'ce-directory-action': 'ce-directory-action',
                'sector': vals,
                'action': 'find-firms-by-sector'
            }

            yield scrapy.FormRequest(url=self.directory, formdata=data, callback=self.parse_sectors)
    
    def parse_sectors(self, response):
        yield {
            "Name": response.xpath('//h3/a/text()').get()
        }

【问题讨论】:

  • 请确保您将表单请求发布到正确的 url 以获取更新的数据

标签: python scrapy


【解决方案1】:

您的代码中有错字:

'ce-directory-action': 'sector-search',

【讨论】:

    猜你喜欢
    • 2018-06-18
    • 2014-06-28
    • 2019-11-11
    • 2018-12-27
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多