无法使用robobrowser操纵形式的输入

时间:2018-07-27 09:45:33

标签: forms robobrowser

我来这里已经整整一天了; Youtube视频中没有一个超出了一个非常基本的示例。请帮忙。我确定我在这里确实缺少一些基本知识。

如果将输入框嵌入表中,是否会有所改变?这是我的代码:

from robobrowser import RoboBrowser

br = RoboBrowser(history=True, parser = 'html.parser', user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11')
br.open('https://fbcad.org/Advanced-Search')
form = br.get_form(id='Form')
form['NameFirst'] = "john"
form['NameLast']  = "smith"
br.submit_form(form)

这是错误:

C:\Python\Python37\python.exe C:/Python/Python37/FBCAD.py
Traceback (most recent call last):
  File "C:/Python/Python37/FBCAD.py", line 7, in <module>
    form['NameFirst'] = "john"
  File "C:\Python\Python37\lib\site-packages\robobrowser\forms\form.py", line 216, in __setitem__
    self.fields[key].value = value
  File "C:\Python\Python37\lib\site-packages\werkzeug\datastructures.py", line 784, in __getitem__
    raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

1 个答案:

答案 0 :(得分:1)

哇,谢谢! 事实证明,答案是不要在这个论坛上提出问题,而是花周末学习硒作为替代方案。谢谢stackoverflow!谢谢Robobrowser!