[Tutor] Open a WebPage with Forms Authentication

Shashwat Anand anand.shashwat at gmail.com
Thu Apr 1 00:16:24 CEST 2010


may be you can try mechanize ?

On Thu, Apr 1, 2010 at 3:41 AM, GoodPotatoes <goodpotatoes at yahoo.com> wrote:

> I would like to sign onto a web page, but am having a difficult time
> determine what parameters to pass in my sign in.  For a simple test, I am
> trying to parse text on a "friends" status page on twitter.  This is not via
> the API, but the web.
>
> import urllib2, urllib, cookielib
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> cj = cookielib.LWPCookieJar()
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> urllib2.install_opener(opener)
> d={'authenticity_token':'8578471445acd12dec39b3353b71c88969f1505e',
> 'username_or_email':'user','password':'pswd123'}
> params = urllib.urlencode(d)
> opener.open('http://twitter.com/login', params)
>
> if not 'id' in [cookie.name for cookie in cj]:
>     raise ValueError, "Login failed"
>
> #########   result
> Traceback (most recent call last):
>   File "<pyshell#12>", line 2, in <module>
>     raise ValueError, "Login failed"
> ValueError: Login failed
>
> How can I tell what the page is asking for, and if I am passing the correct
> parameters?
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100401/fcd3b88c/attachment.html>


More information about the Tutor mailing list