python Mechanize 没有正确解析表单

标签 python parsing mechanize

我正在尝试使用 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/

相关文章:

python - pytorch 运行时错误 : Expected object of scalar type Double but got scalar type Float

c# - 如何根据 SQL 语法在给定元数据信息和解析树的情况下确定 SQL 语句中的列属于哪个表?

java - 如何指定 ANTLR 中某个 token 出现的确切次数?

javascript - 将查询字符串解析为嵌套对象

ruby-on-rails - ruby , Mechanize 。如何获取特定的 <a> 标签文本

asp.net - 使用 Mechanize 绕过 asp 登录

python - 如何将函数应用于列表中的每个元素,然后列出输出?

python - 缺少 'C:\Windows\system32\python27.zip' 文件

python - 如何使用 Bokeh 创建饼图?

ruby - 如何检索内容的 HTML?