gpt4 book ai didi

python - 在 mechanize 上调用浏览器方法时,出现 parse() 错误 : unexpected keyword 'transport_encoding'

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

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

当我检查 Debug模式时,
self._factory 有一个对象,self._factory.global_form 有一个对象
但他们发生了错误。
我穿了什么?
#[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

最佳答案

我尝试应用 Mechanize 0.2.5 版本。
这个版本运行良好。

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

0.2.5现在是稳定版本,(2017-04-29)
http://wwwsearch.sourceforge.net/mechanize/download.html

关于python - 在 mechanize 上调用浏览器方法时,出现 parse() 错误 : unexpected keyword 'transport_encoding' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43671176/

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