python mechanize._html.ParseError
当我运行下面的代码时,我收到 mechanize._html.ParseError 异常。 我该如何让它闭嘴?我知道它是无效的 html,如果它是一个不错的网站,我就不想解析它。我进行了谷歌搜索,并被告知将 br = mechanize.Browser()
替换为 br = mechanize.Browser(factory=mechanize.RobustFactory())
,但这并没有不工作。
import mechanize
#br = mechanize.Browser()
br = mechanize.Browser(factory=mechanize.RobustFactory())
br.set_handle_robots(False)
br.open("http://journeyplanner.irishrail.ie/bin/query.exe")
for form in br.forms():
print form
print
When I run the code below, I get a mechanize._html.ParseError exception.
How do I make it shut up? I know it's invalid html, I wouldn't want to parse it if it was a nice website. I did google around, and was told to replace br = mechanize.Browser()
with br = mechanize.Browser(factory=mechanize.RobustFactory())
, but that didn't work.
import mechanize
#br = mechanize.Browser()
br = mechanize.Browser(factory=mechanize.RobustFactory())
br.set_handle_robots(False)
br.open("http://journeyplanner.irishrail.ie/bin/query.exe")
for form in br.forms():
print form
print
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要使用
mechanize
打开.exe
文件?您应该使用它打开网页。如果您想下载.exe
文件,请使用br.retrieve()
。编辑:
顺便说一句,您的代码为我生成了以下输出:
编辑:
哦,我错了......它根本不是
.exe
文件。我下载了它并用文本编辑器打开,它只是一个.html
文件!它也适用于br = mechanize.Browser()
Why are you opening a
.exe
file withmechanize
? You're supposed to open web pages using that. If you want to download the.exe
file, usebr.retrieve()
instead.Edit:
BTW, your code generated this output for me:
Edit:
Oh, I was wrong... it's not a
.exe
file at all. I downloaded it and opened with a text editor, it's nothing but a.html
file! It also works forbr = mechanize.Browser()