forms - 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
解决方案
推荐阅读
- python - 如何将函数作为参数传递给函数而不调用它?
- radio-button - 大家好,很抱歉在这里写信,我是 RoR 的新手
- c++ - 制作修改由 cc_binary 生成的可执行文件的 Bazel genrule
- memory - 什么是页面转储,因为:VM_BUG_ON_PAGE(page_ref_count(page) == 0)
- c# - 使用 JWT 身份验证调用 REST API 检索数据失败
- apache-kafka - 卡夫卡 SASL_PLAINTEXT SCRAM-SHA-256
- rate - 误分类率
- html - 按钮内的自定义数字
- eclipse - 在 Eclipse 中输入 TFS(Team Foundation Server)URL 时设备登录页面未出现
- javascript - 使用 Javascript 命令或 Selenium 加快浏览器的时间传递