首页 > 解决方案 > Formrequest 和 Scrapy。填写表格

问题描述

我想使用 formrequest 和 scrapy 填写表格。但是,我被卡住了,我不知道如何继续提交表单。如果有人可以帮助我,我将不胜感激。这是我正在使用的代码:

import scrapy
def authentication_failed(response):
# TODO: Check the contents of the response and return True if 
it failed
# or False if it succeeded.
    pass

class IdealistaSpider(scrapy.Spider):
    name = "MiPrimerSpider" 
    custom_settings = {'USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
    }
    start_urls = https://www.idealista.com/inmueble/94342193/']

    def parse(self, response):
       return scrapy.FormRequest.from_response(response,formxpath="//div[@class='modulecontact_form']/form[@class='formcontact']",
       formdata={'contact-email': 'an email','contact-phone':'a number phone','contact-name':'costaman','privacy-policy-checkbox':' ','recommendations-checkbox':None},
        clickdata={'class': 'btn action txt-bold txt-big desktop'},
        callback=self.after_login
    )
    def after_login(self, response):
        if authentication_failed(response):
           self.logger.error("Login failed")
           return

标签: formsscrapysubmit

解决方案


推荐阅读