ParseError:嵌套的FORM

时间:2016-11-22 09:44:56

标签: python mechanize nested-forms

Python mechanize为此代码提供了嵌套的FORMs错误:

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()

这两个都没有解决:

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'

也不是这样:

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'

我在stackoverflow /其他论坛中搜索了python / mechanize中的嵌套表单错误的网页上的Q / A.没有解决方案。

任何(快速)帮助表示赞赏。感谢。

1 个答案:

答案 0 :(得分:0)

看看this question,可能尝试使用BeautifulSoup来解析网站,而不是机械化自己,BS更健壮。