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


Groups > comp.lang.python > #11428

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

From "守株待兔" <1248283536@qq.com>
Subject same code to login,one is ok,another is not
Date 2011-08-15 08:09 +0800
Newsgroups comp.lang.python
Message-ID <mailman.2292.1313367000.1164.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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>

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

same code to login,one is ok,another is not "守株待兔" <1248283536@qq.com> - 2011-08-15 08:09 +0800
  Re: same code to login,one is ok,another is not Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-15 10:55 +1000

csiph-web