same code to login,one is ok,another is not

守株待兔 1248283536 at qq.com
Sun Aug 14 20:09:52 EDT 2011


1.http://www.renren.com/Login.do
it is ok,my code:
import cookielib, urllib2, urllib
 cj = cookielib.CookieJar()
 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
 exheaders = [("User-Agent","Mozilla/4.0 (compatible; MSIE 7.1; Windows NT 5.1; SV1)"),]
 opener.addheaders=exheaders
 url_login = 'http://www.renren.com/Login.do'
 body = (('email','  '), ('password',   '))
 req1 = opener.open(url_login, urllib.urlencode(body))
 file=open('/tmp/sample','w')
 file.write(req1.read())
 file.close()

2.https://passport.baidu.com/?login
can't login,my code:
import cookielib, urllib2, urllib
 cj = cookielib.CookieJar()
 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
 exheaders = [("User-Agent","Mozilla/4.0 (compatible; MSIE 7.1; Windows NT 5.1; SV1)"),]
 opener.addheaders=exheaders
 url_login = 'https://passport.baidu.com/?login'
 body =(('username','  '), ('password','  '),('pwd','1'))
  req1 = opener.open(url_login, urllib.urlencode(body))
 file=open('/tmp/sample','w')
 file.write(req1.read())
 file.close()
what i get is:
<!--STATUS OK--> 
<html><head><title>������§��������      </title> 
<meta http-equiv=content-type content="text/html; charset=gb2312"> 
<META http-equiv='Pragma' content='no-cache'> 
</head> 
<body> 
 
         
             
            <script> 
            var url="./?pwd=1" 
            url=url.replace(/^\.\//gi,"http://passport.baidu.com/"); 
            location.href=url; 
            </script> 
             
         
 
</body> 
</html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110815/cc3c5cd8/attachment.html>


More information about the Python-list mailing list