[Tutor] Web client in Python

Daniel Coughlin kauphlyn@speakeasy.org
Tue, 28 May 2002 20:20:27 -0700 (PDT)


And if you are using windows you can use Ethereal for the same purposes.
http://www.ethereal.com

Usually you dont need to do all that, though.
 
Look at the the page source for your 
login page. 
There is probably an html form on that page that has input tags 
such as <input type="text" name="username">. If you are lucky, you can get away 
with using urllib like so:

import urllib

#note the field names are probably not named 'username' and 'password'

data = urllib.urlencode('username':'yourusername', 'password':'yourpassword') 
urlfile = urllib.urlopen('http://www.yourdomain.com',data)
html = urlfile.readlines()

html will now be a list of lines of page source returned after you post your 
username and password. 

Now if your site uses cookie based authentication, it will be a little trickier. 
You will need to extract the cookie from the headers returned in the section 
above using a command like this

cookie = urlfile.headers.getheader("set-cookie")

Then add this to the headers of future requests using the urllib2 module.

Hope this helps,


Daniel 

  

On Tue, 28 May 2002, Erik Price wrote:

> 
> On Tuesday, May 28, 2002, at 10:02  PM, Kevin Christy wrote:
> 
> > Is there a way that you know of to "log" my session so that I can see 
> > what
> > actually happens behind the scenes (in other words, what the browser and
> > server are passing back and forth to each other)? That would help me
> > automate the process. Thanks!
> 
> If you are using Unix (/Linux/OSX), there are two programs that are 
> available to do exactly this:  tcpdump (captures summary of TCP packets) 
> and tcpflow (captures the actual data those packets are carrying -- 
> inotherwords, probably more useful to what you want to do).
> 
> It's pretty cool, you can just sit there and monitor port 80 on your (or 
> actually anyone else's) machine, or any other port, or redirect it to a 
> file, etc.  Very very instructive in showing exactly what HTTP messages 
> are being passed along (GET/POST/COOKIE vars, etc) during your browser 
> session.
> 
> Can be used for Dark purposes, do not abuse this knowledge.  Search 
> google for a download.  There is no doubt an equivalent program for Win 
> systems if that is your preferred poison, do some hunting.
> 
> 
> Erik
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>