gpt4 book ai didi

python mechanize._html.ParseError

转载 作者:行者123 更新时间:2023-12-04 16:22:32 27 4
gpt4 key购买 nike

当我运行下面的代码时,我得到了一个 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

最佳答案

你为什么要开.exe文件与 mechanize ?您应该使用它打开网页。如果您想下载.exe文件,使用 br.retrieve()反而。

编辑:

顺便说一句,你的代码为我生成了这个输出:

<formular POST http://journeyplanner.irishrail.ie/bin/query.exe/dn?ld=1.1&OK#focus application/x-www-form-urlencoded
<HiddenControl(queryPageDisplayed=yes) (readonly)>
<HiddenControl(HWAI=JS!ajax=yes) (disabled, readonly)>
<HiddenControl(HWAI=JS!js=yes) (disabled, readonly)>
<HiddenControl(outwardConDetails=) (readonly)>
<ImageControl(start=Verbindung suchen)>
<TextControl(REQ0JourneyStopsS0A=255)>
<TextControl(REQ0JourneyStopsS0G=)>
<HiddenControl(REQ0JourneyStopsS0ID=) (readonly)>
<TextControl(REQ0JourneyStopsZ0A=255)>
<TextControl(REQ0JourneyStopsZ0G=)>
<HiddenControl(REQ0JourneyStopsZ0ID=) (readonly)>
<RadioControl(journey_mode=[*single, return])>
<TextControl(REQ0JourneyDate=17/01/2012)>
<SelectControl(REQ0JourneyTime=[*0, 00, 9, 14, 18])>
<HiddenControl(REQ0HafasPeriodToSearch=1440) (readonly)>
<HiddenControl(REQ0HafasPeriodSearch=2) (readonly)>
<HiddenControl(REQ0HafasSearchForw=1) (readonly)>
<CheckboxControl(special_search_both=[1])>
<TextControl(REQ1JourneyDate=)>
<SelectControl(REQ1JourneyTime=[*0, 00, 9, 14, 18])>
<HiddenControl(REQ1HafasPeriodToSearch=1440) (readonly)>
<HiddenControl(REQ1HafasPeriodSearch=2) (readonly)>
<HiddenControl(REQ1HafasSearchForw=1) (readonly)>
<SubmitControl(start=Go) (readonly)>
<SubmitControl(start=Go) (readonly)>>

编辑:

哦,我错了...它不是 .exe文件。我下载了,用文本编辑器打开,就是 .html文件!它也适用于 br = mechanize.Browser()

关于python mechanize._html.ParseError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8899748/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com