I want to make a function in PyQt evaluateJavaScript() (or may be similar one) and than display a result of evaluated function. Real function will be much bigger, and it might not be a string.
I'm only interesting in how to create a function inside PyQt code and than get the result into python variable.
To be more clear I will give you an example:
that's the js that I want to type in after loadFinished
on http://jquery.com:
w = document.getElementsByTagName('p')[0];
w.innerHTML
If I do it in browser console, I' will get an output:
"jQuery is a fast and concise JavaScript Library ...... blah blah blah"
And I want to store this output in a variable.
#!/usr/bin/env python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
import os, sys, signal
from urllib2 import urlopen
class GBot(QWebView):
def __init__(self):
QWebView.__init__(self)
self.setPage(BrowserSettings())
#self.jquery = get_jquery()
self.load(QUrl('http://jquery.com'))
self.frame = self.page().currentFrame()
def _loadFinished(self, ok):
doc = self.frame.documentElement()
#doc.evaluateJavaScript(self.jquery)
r = doc.evaluateJavaScript('''w = document.getElementsByTagName('p')[0]; w.innerHTML''')
print r #want to do something like this
if __name__ == '__main__':
app = QApplication(sys.argv)
bot = GBot()
bot.show()
if signal.signal(signal.SIGINT, signal.SIG_DFL):
sys.exit(app.exec_())
app.exec_()