【问题标题】:python's mechanize wont properly parse a formpython mechanize 无法正确解析表单
【发布时间】:2010-09-19 04:48:44
【问题描述】:

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

是否有办法检索页面的 html 并对其进行编辑,并根据检索到的 HTML 进行机械化解析和提交表单?

【问题讨论】:

    标签: python parsing mechanize


    【解决方案1】:

    如果其他人有兴趣。在 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 2021-09-26
      • 1970-01-01
      • 2014-10-10
      相关资源
      最近更新 更多