log in to a website

P

passion_to_be_free

I'm learning python, and my goal is to write a script that will log
into a website for me. The site uses HTTPS, the form uses the "POST"
method.
From what I've been able to find so far, it looks like i need to use
the urllib2 module...does anyone know where I can find some good sample
code to read up on how to do this?

-Thx
 
J

Jeff Epler

You may find the third-party modules "ClientForm" and "ClientCookie" to
be useful.

Using ClientForm, the following code uploads a file to a particular web form:
forms = ClientForm.ParseResponse(urllib2.urlopen(url))
f = forms[0]
f.add_file(open(local, "rb"), filename=remote, name="file")
u = f.click("attach")
urllib2.urlopen(u)

A web search should turn up the homepage for these modules.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFCsdDgJd01MZaTXX0RAn3kAKCLB2/JuT7rdbJ7ZpfYGgNp/uFhmACfZAYx
zJ63Lz+w4ecz539Tcw7StuU=
=UE89
-----END PGP SIGNATURE-----
 
F

Fuzzyman

I'm learning python, and my goal is to write a script that will log
into a website for me. The site uses HTTPS, the form uses the "POST"
method.

the urllib2 module...does anyone know where I can find some good sample
code to read up on how to do this?

-Thx

Is it just BASIC authentication ? (http error code 401).

Clientform is still worth investigating - but if you want help on BASIC
authentication then checkout
http://www.voidspace.org.uk/python/articles/authentication.shtml

Best Regards,

Fuzzyman
http://www.voidspace.org.uk/python
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top