[Tutor] automate add-to-cart with python

Francois Dion francois.dion at gmail.com
Tue Jan 29 21:12:11 CET 2013


On Mon, Jan 28, 2013 at 6:32 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> 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...

The other way around does exists, python in your web browser:
http://brython.info

Did a quick iPhone web app that way and demoed it to our local Python
group last night:
http://raspberry-python.blogspot.com/2013/01/iphone-app-with-python.html

You could easily extend this concept where your python script server
side controls your python script client side through reverse Ajax. And
of course it's also possible to do the whole thing client side,
without a server. Works on all modern browsers too.

François

--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion


More information about the Tutor mailing list