2011/8/14 守株待兔 <1248283...@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 -- http://mail.python.org/mailman/listinfo/python-list