选择表单时 Python Mechanize 错误

标签 python python-2.7 mechanize

我要提交的网站代码::: FORM PART OF WEBSIDE CODE


当我尝试选择表单时发生错误

Traceback (most recent call last):
  File "call.py", line 35, in <module>
    loginAccount()
  File "call.py", line 15, in loginAccount
    browser.select_form(nr = 0)
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 499, in select_form
    global_form = self._factory.global_form
  File "/usr/lib/python2.7/dist-packages/mechanize/_html.py", line 544, in __getattr__
    self.forms()
  File "/usr/lib/python2.7/dist-packages/mechanize/_html.py", line 557, in forms
    self._forms_factory.forms())
  File "/usr/lib/python2.7/dist-packages/mechanize/_html.py", line 237, in forms
    _urlunparse=_rfc3986.urlunsplit,
  File "/usr/lib/python2.7/dist-packages/mechanize/_form.py", line 844, in ParseResponseEx
    _urlunparse=_urlunparse,
  File "/usr/lib/python2.7/dist-packages/mechanize/_form.py", line 981, in _ParseFileEx
    fp.feed(data)
  File "/usr/lib/python2.7/dist-packages/mechanize/_form.py", line 760, in feed
    raise ParseError(exc)
mechanize._form.ParseError: expected name token at '<!\\\\])/g,"\\\\$1").rep'

源代码(我写了像# ERROR OCCUR HERE这样的评论):

   browser = mechanize.Browser()
   browser.set_handle_robots(False)
   browser.set_handle_refresh(False)
   browser.open("https://accounts.google.com/ServiceLoginAuth")
   browser.select_form(nr = 0)
   browser.form['Email'] = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abe6f2e6eae2e7ebccc6cac2c785c8c4c6" rel="noreferrer noopener nofollow">[email protected]</a>"
   browser.form['Passwd'] = "MYPASWORD"
   browser.submit() # Till the here, works fine. I can login.

   resp = browser.open("https://accounts.google.com/b/0/SmsAuthSettings?Setup=1")
   resp = resp.read()
   browser.select_form(nr = 0) # ERROR OCCUR HERE

当我删除 browser.select_form(nr = 0) 时,程序运行正常。 我该怎么办?

最佳答案

使用更强大的解析器, 例如 浏览器= mechanize.Browser(factory=mechanize.RobustFactory())

查看此链接以获得更多帮助: http://www.thecodingforums.com/threads/mechanize-select_form-issue.359575/

关于选择表单时 Python Mechanize 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28889990/

相关文章:

python - 使用 PIL 和请求下载图像

python - 如何在 python 2.7 中删除 ) ' 和 , ?

ruby-on-rails - 未定义的方法错误单击简单的 webscraper

python - 在 stdscr 中解释 "ENTER"按键(Python 中的 curses 模块)

python - 在 trac 上使用 mercurial 时为 "DLL load failed"

python - 在 QTextEdit 小部件中解析和显示 HTML

python - 递归逆 FFT

Python,正则表达式动态计数

Python Mechanize 表单提交不起作用

ruby - 尝试使用 ruby​​ Mechanize POST