简体   繁体   English

如何使用FormRequest发布具有多个相同名称输入的表单?

[英]How to use FormRequest to post forms with several same name inputs?

I am writing a web crawler with scrapy to deal with forms. 我正在编写一个爬虫,用于处理表单。 The problem is that I have encountered a form with a lot of inputs with the same name. 问题是我遇到了一个表单,其中包含很多同名输入。 The tags are like these: 标签如下:

<input type="text" name="CRN_IN" size="6" maxlength="5" ID="crn_id1" />
<input type="text" name="CRN_IN" size="6" maxlength="5" ID="crn_id2" />
<input type="text" name="CRN_IN" size="6" maxlength="5" ID="crn_id3" />

The only thing to distinguesh them is the ID attribute. 区分它们的唯一方法是ID属性。 And I want to fill the one whoes ID='crn_id1' with some number. 我想用一些数字填充whoes ID ='crn_id1'。 However as far as I kown scrapy can only fill blanks with the name attribute using formdata from the from_response method. 但是据我所知,scrapy只能使用from_response方法中的formdata用name属性填充空白。 Could anybody tell me how to use the from_response method to solve my problem. 谁能告诉我如何使用from_response方法来解决我的问题。 Or is there any other methods to solve(but within scrapy). 还是有其他方法可以解决(但是很麻烦)。 Thank you very much. 非常感谢你。

Here is part of the html code from the website. 这是该网站html代码的一部分。 Input with same names 输入同名

The from_response method is only a helper to populate the input arguments of the specified form you want to request, but it is still a FormRequest where you can always override the formdata argument to send your own input arguments: from_response方法只是用来填充您要请求的指定表单的输入参数的助手,但它仍然是一个FormRequest ,您可以始终重写formdata参数以发送自己的输入参数:

yield FormRequest.from_response(
    response=response,
    formdata={
        myinput='myvalue',
    }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM