Python interacting with Java Script webpage?

Syver Enstad syver at NOSPAMcyberwatcher.com
Wed Mar 14 16:01:55 CET 2001


Use urllib or httplib, these are very simple to use and there are good
examples in the docuementation.

Find out what the names of the form fields are and use these in the
dictionary you use to send the form data

Both urllib and httplib returns a filelike object that is easy to stream out
to disk,

In addition urllib has got a method that writes the content to disk,
urllib.urlretrieve

Here is an example using urlopen:

The form fields used here would be syver, christine, marius.

file = urllib.urlopen('http://localhost/test/testform.asp',
data=urllib.urlencode({'syver': 30, 'christine': 33, 'marius': 30}))

The data parameter is where you pass in the form content. The easiest way is
as shown by using a dictionary and the urllib.urlencode function that
converts the dictionary into a format that you can use for query strings or
form posts.

an example using urlretrieve
ret = urllib.urlretrieve('http://localhost/test/testform.asp',
filename='form.txt', data=urllib.urlencode({'syver': 30, 'christine': 33,
'marius': 30}))

as you can see it's almost equal to urlopen, but you also specify a filename
that urlretrieve will write the content to.

Hope this helps you and doing what you want to do.


"William Dandreta" <wjdandreta at worldnet.att.net> wrote and wrote
> I would like to write a Python program that will be able to connect to a
> webpage that runs a Java Script, post data to the form displayed, and save
> the data retrieved to a file.






More information about the Python-list mailing list