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.

1
  • Please be more specific on what is it exactly that you are trying to achieve, and if possible, add some example code to your post Commented May 13, 2013 at 10:23

1 Answer 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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much,It is of great help to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.