Python 在mechanize上调用浏览器方法时,我遇到一个parse()错误:意外的关键字';传输编码';

Python 在mechanize上调用浏览器方法时,我遇到一个parse()错误:意外的关键字';传输编码';,python,mechanize,Python,Mechanize,我正在尝试使用mechanize提交表单。 但我可以从mechanize浏览器获取任何网页信息。 我不知道如何解决这个问题。。。。 请帮帮我 这是我的代码和错误结果。 在代码中,当调用browser.title()、browser.select_form()时,我遇到了一个解析错误,无法找到关键字“transport_encoding” 代码: browser = mechanize.Browser() cj = cookielib.LWPCookieJar() browser.set_cook

我正在尝试使用mechanize提交表单。 但我可以从mechanize浏览器获取任何网页信息。 我不知道如何解决这个问题。。。。 请帮帮我

这是我的代码和错误结果。 在代码中,当调用browser.title()、browser.select_form()时,我遇到了一个解析错误,无法找到关键字“transport_encoding”

代码:

browser = mechanize.Browser()
cj = cookielib.LWPCookieJar()
browser.set_cookiejar(cj)
browser.set_handle_equiv(True)
browser.set_handle_redirect(True)
browser.set_handle_robots(False)
browser.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
browser.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.3"')]

response = browser.open(u'https://www.google.com/')
print(browser.title())
print(response.geturl())
print(response.info())
print(response.read())
browser.select_form(nr=0)
browser.select_form(name=u'Form1')
# for form in self.browser.forms():
#   print (form)
错误消息:

Traceback (most recent call last):
File "D:/Projects/DormFilter/DormCrawler/Connector.py", line 168, in <module>
    print(browser.title())
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 561, in title   
    return self._factory.title
File "C:\Python27\lib\site-packages\mechanize\_html.py", line 254, in title
    self.root) if self.root is not None else None
File "C:\Python27\lib\site-packages\mechanize\_html.py", line 247, in root
    response, verify=False))
File "C:\Python27\lib\site-packages\mechanize\_html.py", line 149, in content_parser
    namespaceHTMLElements=False)
TypeError: parse() got an unexpected keyword argument 'transport_encoding'

我尝试应用mechanize 0.2.5版本。 这个版本很好用

如果有人遇到同样的问题,尝试使用其他版本

0.2.5现在是一个稳定的版本(2017-04-29)

#[This code is an library code]
def title(self):
    ' Return title, or None if there is no title element in the document. '
    if not self.viewing_html():
        raise BrowserStateError("not viewing HTML")
    return self._factory.title

def select_form(self, name=None, predicate=None, nr=None, **attrs):
    if not self.viewing_html():
        raise BrowserStateError("not viewing HTML")
    if name is None and predicate is None and nr is None and not attrs:
        raise ValueError("at least one argument must be supplied to specify form")

    global_form = self._factory.global_form
    if nr is None and name is None and predicate is not None and predicate(
            global_form):
        self.form = global_form
        return