[Tutor] automate add-to-cart with python

Alan Gauld alan.gauld at btinternet.com
Tue Jan 29 00:32:43 CET 2013


On 28/01/13 22:51, Benjamin Fishbein wrote:
> In general, despite scouring the Internet, I haven't been able to figure
> out how to get Python to cause javascripts I find in the html to be run.

That's because Javascript is run in the browser which has a Javascript 
interpreter built in. Python doesn't have a Javascript interpreter so 
can't run Javascript.

But that's usually the wrong thing to do anyway so it doesn't matter. 
What you need to do is figure out what the Javascript is doing - usually 
sending some data to a server - and replicate that.

Alternatively fire up a real browser and drive that with automation. How 
you do that will largely depend on the browser and the OS.

Or maybe, just maybe, somebody has written a javascript interpreter in 
Python as a module that you can import. It sounds just about crazy 
enough that it might even exist! But as I said, that's probably the 
wrong thing to do...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list