2

I used python's 2to3.py to do the fixing on spynner module. Then there seemed to be an issue with QString on python 3. I modified the browser.py in spynner with QString = str as some users suggested. For a start I tried the following code

import spynner
browser = spynner.Browser()
browser.set_proxy("http://username:password@host:3128")
browser.load("http://www.google.com/")

Now python is throwing the following error

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 is defined in browser.py as

res = self.webframe.evaluateJavaScript(jscode)

Does spynner actually work on python 3?

feminkk
  • 1,135
  • 2
  • 14
  • 18

1 Answers1

0

This worked for me. Change this line

js_has_runned_successfully = res.isNull() or res.isValid()

to these lines:

if res is None:
      js_has_runned_successfully = True
else:
      js_has_runned_successfully = isinstance(res, str)

I don't think there is any plans to make spynner work with python 3 https://github.com/kiorky/spynner/issues/9. However I was able to use it by running these sed commands (I didn't try to fix the entire code base I was just looking to get it working on my application):

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.py
tluyet
  • 1
  • 1