python mechanize将无法正确解析表单

时间:2010-09-19 04:48:45

标签: python parsing mechanize

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

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

1 个答案:

答案 0 :(得分:2)

如果有其他人有兴趣。在机械化常见问题解答中找到答案。

或者,您可以任意处理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)