gpt4 book ai didi

python Mechanize 没有正确解析表单

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

我正在尝试使用 python 的 Mechanize 提交表单,但它无法正确解析有问题的表单。除了这一种形式外,还有 4 种其他形式可以正确解析。尽管在 perl 的 www::mechanize 中正确解析了该表单,但我想坚持使用 python。

无论如何检索页面的html并对其进行编辑并根据检索到的HTML获取 Mechanize 来解析和提交表单?

最佳答案

如果其他人有兴趣。在 Mechanize 的常见问题解答中找到了答案。

或者,您可以任意处理 HTML(和标题):

browser = mechanize.Browser()
browser.open("http://example.com/")
html = browser.response().get_data().replace("<br/>", "<br />")
response = mechanize.make_response(
html, [("Content-Type", "text/html")],
"http://example.com/", 200, "OK")
browser.set_response(response)

关于python Mechanize 没有正确解析表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3744544/

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