ParseError: nested FORMs

为君一笑 提交于 2019-12-12 04:23:34

问题


Python mechanize gives nested FORMs error for this code:

url = 'http://bis.zju.edu.cn/psi/'
browse = mechanize.Browser()
browse.set_handle_robots(False)
browse.open(url)

# print [n for n in browse.forms()]
# ParseError: nested FORMs

browse.select_form(name="form1") # or (nr=0)
# ParseError: nested FORMs

seq = '>seq1' + '\n' + 'MNANSSAKLGDSA'
browse['sequence'] = seq
response = browse.submit()

Neither this solves:

browse = mechanize.Browser(factory=mechanize.RobustFactory())
browse.set_handle_robots(False)
browse.open(url)

print [n for n in browse.forms()]
# [] # empty list

browse.select_form(name="form1") # or (nr=0)
# FormNotFoundError: no form matching name 'form1'

Nor this:

browse = mechanize.Browser()
browse.set_handle_robots(False)
response = browse.open(url)
# 'modify response' (anyway? to remove erroneous html?)
browse.set_response(response)

print [n for n in browse.forms()]
# [] # empty list

browse.select_form(name="form1") # or (nr=0)
# FormNotFoundError: no form matching name 'form1'

I have searched net for Q/A on nested forms error in python/mechanize in stackoverflow/ other forums. No solutions.

Any (quick) help is appreciated. Thanks.


回答1:


Take a look at this question, and possibly try using BeautifulSoup to parse the website instead of mechanize itself, BS is a little bit more robust.



来源:https://stackoverflow.com/questions/40738461/parseerror-nested-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!