Python simulate browser activity

Chris Angelico rosuav at
Fri Mar 16 20:20:17 CET 2012

On Fri, Mar 16, 2012 at 1:23 PM, choi2k <rex.0510 at> wrote:
> The application aims to simulate user activity including visit a
> website and perform some interactive actions (click on the menu,
> submit a form, redirect to another pages...etc)
> I have found some libraries / plugins which aims to simulate browser
> activity but ... none of them support AJAX request and/or running
> javascript.
> Here is one of the simple tasks which I would like to do using the
> application:
> 4. post ajax request using javascript and if the page has been
> redirected, load the new page content

To the web server, everything is a request. Don't think in terms of
Javascript; there is no Javascript, there is no AJAX, there is not
even a web browser. There's just a TCP socket connection and an HTTP
request. That's all you have.

On that basis, your Python script most definitely can simulate the
request. It needs simply to make the same HTTP query that the
Javascript would have made. The only tricky part is figuring out what
that request would be. If you can use a non-SSL connection, that'll
make your job easier - just get a proxy or packet sniffer to monitor
an actual web browser, then save the request headers and body. You can
then replay that using Python; it's not difficult to handle cookies
and such, too.

Hope that helps!


More information about the Python-list mailing list