1

I am learning pyqt,use for parse webpage.

Now i want use pyqt evaluate javascript function just like this answer do: spidermonkey evaluate js function which in remote js file


import urllib2
import spidermonkey
js = spidermonkey.Runtime()
js_ctx = js.new_context()
script = urllib2.urlopen('http://etherhack.co.uk/hashing/whirlpool/js/whirlpool.js').read()
    js_ctx.eval_script(script)
    js_ctx.eval_script('var s = "abc"')
    js_ctx.eval_script('print(HexWhirlpool(s))')

I want know how to achieve the same effect by using pyqt instead of spidermonkey.

4

1 回答 1

0

PyQt is a UI framework, so it might not be the best arrow in your quiver.

You can use WebView to load and display the web page. Since WebView uses WebKit, it will load and parse the HTML and all CSS and JavaScript in it. But that means you just get the final result - you don't have much control what is loaded and when.

Or you can use a tool like Beautiful Soup to parse the HTML. This gives you full control. You can then try to use spidermonkey to run the JavaScript but that will fail since many global variables like window or document will be missing. Also, there won't be a DOM.

For this, you'd need something like Envjs but there is no Python integration.

Maybe PhantomJS (a script driven Chrome/Chromium browser) is an option. See this question: Is there a way to use PhantomJS in Python?

于 2013-05-13T12:37:04.577 回答