使用 scrapy 选择单选按钮
我将如何使用 scrapy 选择单选按钮?
我正在尝试选择以下内容
formdata={'rd1':'E'} does not work
<input type="radio" name="rd1" value="E" checked="checked" />Employee
<input type="radio" name="rd2" value="o" />Other
How would i go about selection radio buttons with scrapy?
I am trying to select the following
formdata={'rd1':'E'} does not work
<input type="radio" name="rd1" value="E" checked="checked" />Employee
<input type="radio" name="rd2" value="o" />Other
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 lxml.cssselector 来选择单选按钮。
You could use lxml.cssselector to select the radio buttons.
我刚刚遇到了类似的问题(当然这就是我来这里的原因)。芝加哥市的这个精彩网站(https://webapps1.chicago.gov/buildingrecords/home) 要求您的机器人通过单选按钮和单击按钮来“同意”他们的“免责声明”(这确实非常有趣!)。我在
scrapy.FormRequest.from_response
的帮助下解决了这个问题:与页面代码一起,它非常不言自明。您可能还需要此处描述的表单的其他参数:https://docs.scrapy.org/en/latest/topics/request-response.html?highlight=FormRequest()#scrapy.http.FormRequest.from_response
PS下一页的谜语也可以用同样的方式解决。 :)
I've just bumped into a similar problem (that's why I'm here of course). This wonderful site of the City of Chicago (https://webapps1.chicago.gov/buildingrecords/home) requires your bot to 'Aggree' to their 'liability disclaimer' (this is very funny indeed!) with a radio-button and a click on a button. I solved the problem with the help of
scrapy.FormRequest.from_response
:Together with the code of the page it's pretty self-explanatory. You may also need other parameters of your form described here: https://docs.scrapy.org/en/latest/topics/request-response.html?highlight=FormRequest()#scrapy.http.FormRequest.from_response
P.S. The next pages' riddle is solvable too in the same way. :)