How to access my internet account without using browser.

Eric Lorenzo zo at angband.org
Thu Aug 3 10:06:20 EDT 2000


Sam Wun <swun at eSec.com.au> writes:
> I still want to login to it without using browser, how
> can I do that in python?
> 
> I wnat to be able to navigate Website A something like:
> 
> Login Website A using Python program -> main page of Website A -> page 1
> -> page 2 -> page3 -> pageN

Chances are, 'logging in' to the site involves accepting some cookies.
What you'll need to do is connect to the site using httplib or
somesuch, POSTing whatever login information the site wants
(i.e. username/password), and then parsing the response to store any
cookies the host sends.  Then the program will need to re-send those
cookies with any requests where they will be expected.  Your program
will probably also need to be smart enough to follow redirects.  Once
you've logged in to the site, you'll need to follow links to actually
get to what you want.  If the links don't change much, you can just
hard-code them into your program, or put them into a configuration
file.  If the links change with every session, you'll need to make
your program parse them out of the HTML that the site has returned to
you.

I actually wrote a program a while back that needed to do a number of
the things you describe.  Since it was my first Python program of any
size, it is perhaps not the nicest from the style point of view.
(Also, I wanted to be able to distribute my program as a single
script, so I crammed a lot of things into one file that really should
have been split into multiple modules.)  But it might be useful to
you, anyways.  The source can be found at:

http://www.arsdigita.com/free-tools/profile_site.txt

The classes that will probably interest you most are CookieDict and
HTTPUserAgent.  A couple of caveats: HTTPUserAgent is really anal
about redirect headers that don't meet the specs, and both classes are
built with the assumption that you'll be dealing with the same
hostname the whole time.

Eric



More information about the Python-list mailing list