Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21771

Re: Python simulate browser activity

References <214c4c0c-f8ec-4030-946b-8becc8e1aa9c@ur9g2000pbc.googlegroups.com>
Date 2012-03-17 06:20 +1100
Subject Re: Python simulate browser activity
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.731.1331925620.3037.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Mar 16, 2012 at 1:23 PM, choi2k <rex.0510@gmail.com> 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!

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python simulate browser activity choi2k <rex.0510@gmail.com> - 2012-03-15 19:23 -0700
  Re: Python simulate browser activity Chris Rebert <clp2@rebertia.com> - 2012-03-15 19:54 -0700
  Re: Python simulate browser activity Jerry Hill <malaclypse2@gmail.com> - 2012-03-15 23:44 -0400
  Re: Python simulate browser activity Roy Smith <roy@panix.com> - 2012-03-16 08:57 -0400
  Re: Python simulate browser activity Chris Angelico <rosuav@gmail.com> - 2012-03-17 06:20 +1100
  Re: Python simulate browser activity NA <NA> - 2012-03-16 21:51 -0400

csiph-web