Question

EDIT: While the original problem is solved, the code fails to actually do anything. Tested in Chrome, it inserts 'hi' into the password box. In Spynner it simply loads the page.

I'm attempting to use Spynner to scrape a website my school uses to provide online timetables. For some reason, I always get the following error:

Run Javascript code: jq("[class^=login-text-box]").val("hi")
Javascript console: ReferenceError: Can't find variable: jq

This is caused by the following code:

import spynner

browser = spynner.Browser()
browser.debug_level = 3;
browser.show()
browser.load("http://web.edval.com.au/#publicaccess")
browser.runjs('_jQuery("[class^=login-text-box]").val("hi")')
browser.close()

I have also tried:

import spynner

browser = spynner.Browser()
browser.debug_level = 3;
browser.jslib = 'jq'
browser.show()
browser.load("http://web.edval.com.au/#publicaccess")
browser.runjs('jq("[class^=login-text-box]").val("hi")')
browser.close()

with an equal lack of success. Pasting the JavaScript command into Chrome's JS Console (after I've injected jQuery) works perfectly.

Please could someone offer some assistance?

Thanks!

Was it helpful?

Solution

Never mind, even though the docs said jQuery would be loaded as _jQuery, it was actually loaded as $. I fixed it by changing my code to:

import spynner

browser = spynner.Browser()
browser.load_jquery(True)
browser.debug_level = 3;
browser.show()
browser.load("http://web.edval.com.au/#publicaccess")
browser.runjs(browser.jslib+'("[class^=login-text-box]").val("hi")')
browser.close()

Note that runjs now actually checks browser.jslib.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top