formdata={'rd1':'E'} does not work
<input type="radio" name="rd1" value="E" checked="checked" />Employee
<input type="radio" name="rd2" value="o" />Other
def agreement_failed(response):
# check the result of your first post here
return # something if it's a failure or nothing if it's not
class InspectionsListSpider(scrapy.Spider):
name = 'inspections_list'
start_urls = ['https://webapps1.chicago.gov/buildingrecords/home']
def parse(self, response):
return scrapy.FormRequest.from_response(
response,
formid='agreement',
formdata = {"agreement": "Y",
"submit": "submit"},
callback = self.after_agreement
)
def after_agreement(self, response):
if agreement_failed(response):
self.logger.error("agreement failed!")
return
else:
... # whatever you are going to do after
您可以使用lxml.cssselector选择单选按钮。在
我刚刚遇到了一个类似的问题(这就是我来这里的原因)。芝加哥城的这个奇妙的网站(https://webapps1.chicago.gov/buildingrecords/home)要求你的机器人“Aggree”他们的“责任免责声明”(这确实很有趣!)用单选按钮和单击按钮。我在
scrapy.FormRequest.from_response
的帮助下解决了这个问题:加上页面的代码,这是不言而喻的。您可能还需要此处描述的表单的其他参数:https://docs.scrapy.org/en/latest/topics/request-response.html?highlight=FormRequest()#scrapy.http.FormRequest.from_response
下一页的谜语也是可以用同样的方法来解决的。:)
相关问题 更多 >
编程相关推荐