使用python Mechanize修复网页的字符编码

使用python Mechanize修复网页的字符编码,python,mechanize,Python,Mechanize,我正在尝试使用Mechanize提交关于此的表格 br.open("http://mspc.bii.a-star.edu.sg/tankp/run_depth.html") #selecting form to fill br.select_form(nr = 0) #input for the form br['pdb_id'] = '1atp' req = br.submit() 但是,这会产生以下错误 mechanize._form.ParseError: expected name t

我正在尝试使用Mechanize提交关于此的表格

br.open("http://mspc.bii.a-star.edu.sg/tankp/run_depth.html")
#selecting form to fill
br.select_form(nr = 0)
#input for the form
br['pdb_id'] = '1atp'
req = br.submit()
但是,这会产生以下错误

mechanize._form.ParseError: expected name token at '<! INPUT PDB FILE>\n\t'
mechanize.\u form.ParseError:在'\n\t'处应有名称标记

我想这是因为一些错误的字符编码。我想知道如何解决这个问题。

您的问题有些不正确,导致一个无效的网站,mechanize的解析器无法读取该网站。但是您可以这样做,这在我的情况下是有效的(Python 2.7.9,mechanize 0.2.5):

#/usr/bin/env python
#-*-编码:utf-8-*-
进口机械化
br=mechanize.Browser(工厂=mechanize.RobustFactory())
br.公开发行('http://mspc.bii.a-star.edu.sg/tankp/run_depth.html')
br.选择表格(nr=0)
br['pdb_id']=“1atp”
响应=br.submit()