login with python (2)

Fredrik Lundh fredrik at pythonware.com
Sat Jul 13 08:20:59 EDT 2002


Ralf Claus wrote:

> Hello, the login website of my router needs the following
> html code to login:
>
> <form action="http://192.168.2.1:/login.htm" method="post" name="aa">
> <INPUT type="password" maxLength=4 size=6 name=pass></td><p>
> <input type="hidden" name="site" value="go">
> </form>

something like this could work (untested):

    import urllib

    LOGIN = "http://192.168.2.1:/login.htm"

    SITE = "go"
    PASSWORD = "..."

    data = urllib.urlencode({"site": SITE, "password": PASSWORD})
    file = urllib.urlopen(LOGIN, data)

    print file.headers
    print file.read()

study the headers and the page contents carefully to see what
you need to do next (the site may be forwarding you somewhere,
possibly using javascript; it may use cookies, etc)

</F>

<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->






More information about the Python-list mailing list