我使用python的2to3.py来修复spynner模块。然后,在python 3上似乎出现了QString的问题。正如一些用户建议的那样,我用QString = str在spynner中修改了browser.py。首先,我尝试了以下代码
import spynner
browser = spynner.Browser()
browser.set_proxy("http://username:password@host:3128")
browser.load("http://www.google.com/")现在python正在抛出以下错误
File "G:\Python33\lib\site-packages\spynner\browser.py", line 1163, in runjs
js_has_runned_successfully = res.isValid() or res.isNull()
AttributeError: 'str' object has no attribute 'isValid'res在browser.py中定义为
res = self.webframe.evaluateJavaScript(jscode)spynner真的在python 3上工作吗?
发布于 2020-07-15 13:41:23
这对我有用。更改这一行
js_has_runned_successfully = res.isNull() or res.isValid()到以下几行:
if res is None:
js_has_runned_successfully = True
else:
js_has_runned_successfully = isinstance(res, str)我不认为有任何计划使spynner与python3 https://github.com/kiorky/spynner/issues/9一起工作。但是,我能够通过运行这些sed命令来使用它(我没有试图修复整个代码库,我只是想让它在我的应用程序上运行):
sed -i "s/from PyQt4.QtCore import SIGNAL, QUrl, QString, Qt, QEvent/from PyQt4.QtCore import SIGNAL, QUrl, Qt, QEvent/g" browser.py
sed -i "s/if isinstance(s, QString)/if isinstance(s, str)/g" browser.py
sed -i "s/js_has_runned_successfully = res.isNull() or res.isValid()/if res is None:\n js_has_runned_successfully = True\n else:\n js_has_runned_successfully = isinstance(res, str)/g" browser.py
sed -i "s/.toUtf8()/.encode('utf-8')/g" browser.pyhttps://stackoverflow.com/questions/16080230
复制相似问题