Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11395
| References | <tencent_6DD52AA454BF5A964A9B1269@qq.com> |
|---|---|
| Date | 2011-08-14 08:07 -0700 |
| Subject | Re: login with urllib2 |
| From | Chris Rebert <clp2@rebertia.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2274.1313334460.1164.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: login with urllib2 Chris Rebert <clp2@rebertia.com> - 2011-08-14 08:07 -0700
csiph-web