Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11395 > unrolled thread

Re: login with urllib2

Started byChris Rebert <clp2@rebertia.com>
First post2011-08-14 08:07 -0700
Last post2011-08-14 08:07 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: login with urllib2 Chris Rebert <clp2@rebertia.com> - 2011-08-14 08:07 -0700

#11395 — Re: login with urllib2

FromChris Rebert <clp2@rebertia.com>
Date2011-08-14 08:07 -0700
SubjectRe: login with urllib2
Message-ID<mailman.2274.1313334460.1164.python-list@python.org>
2011/8/14 守株待兔 <1248283536@qq.com>:
> please to see my code:
> import urllib
> import urllib2
>
> url = 'http://hi.baidu.com/'
> values = {'username' : '******','password' : '******' }
>
> data = urllib.urlencode(values)
> req = urllib2.Request(url,data)
> response = urllib2.urlopen(req)
> the_page = response.read()
>
> i can't to login ,why?username and password  are  right.
> any word  appreciated.

Use the URL specified as the <form>'s action, which in this case is
https://passport.baidu.com/?login , rather than the URL of the login
page itself.
The <form> fields aren't called "username" and "password"; read the
page's HTML. You'll also see that there are a few hidden form fields
that are probably required.
Finally, even if you fix these problems, the site could possibly block
Python based on its User-agent header.

Cheers,
Chris
--
http://blog.rebertia.com

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web