使用python-Mechaniz修复网页字符编码

2024-10-01 22:39:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图使用Mechanize提交关于此page的表单。在

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

但是,这会产生以下错误

^{pr2}$

我想这是因为一些错误的字符编码(ref)。我想知道怎么解决这个问题。在


Tags: brformhttp表单错误pageopensg
1条回答
网友
1楼 · 发布于 2024-10-01 22:39:21

您的问题是某个损坏的HTML comment tags,导致mechanize的解析器无法读取的无效网站。但是您可以改为use the included BeautifulSoup parser,这在我的例子中有效(python2.7.9,mechanize0.2.5):

#!/usr/bin/env python
#-*- coding: utf-8 -*-
import mechanize

br = mechanize.Browser(factory=mechanize.RobustFactory())
br.open('http://mspc.bii.a-star.edu.sg/tankp/run_depth.html')
br.select_form(nr=0)
br['pdb_id'] = '1atp'
response = br.submit()

相关问题 更多 >

    热门问题