[Python] 51CTO自动登录,领下载豆,领无忧币 →→→→→进入此内容的聊天室

来自 , 2019-12-03, 写在 Python, 查看 218 次.
URL http://www.code666.cn/view/4be49c79
  1. #coding:UTF-8
  2.  
  3. import urllib,urllib2,cookielib,re,random
  4.  
  5. class Login:
  6.     _login_url = 'http://home.51cto.com/index.php?s=/Index/doLogin'
  7.     _method = 'post'
  8.     #email 51cto登录用户名或邮箱
  9.     #passwd 51cto登录密码
  10.     _login_data = {
  11.                    'email':'****',\
  12.                    'passwd':'****',\
  13.             }
  14.     _headers = [
  15.                 ('host','home.51cto.com'),\
  16.                 ('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2'),\
  17.                 ('Referer','http://home.51cto.com/index.php?s=/Index/index/reback/http%253A%252F%252Fwww.51cto.com%252F/')\
  18.         ]
  19.     _data = {
  20.              'cookie_file_path':'./51cto_cookies.dat'
  21.         }
  22.     _re = r'src="(.+?)"'
  23.     _version = '0.1'
  24.     _connect_info = {}
  25.     def __init__(self):
  26.         self._connect_info['cookie'] = cookielib.LWPCookieJar()
  27.         try:
  28.             self._connect_info['cookie'].revert(self._data['cookie_file_path'])
  29.         except Exception,e:            
  30.             print e
  31.         self._connect_info['cookie_processor'] = urllib2.HTTPCookieProcessor(self._connect_info['cookie'])
  32.         self._connect_info['post_data'] = urllib.urlencode(self._login_data)
  33.     def open(self):
  34.         opener = urllib2.build_opener(self._connect_info['cookie_processor'])
  35.         opener.addheaders = self._headers
  36.         urllib2.install_opener(opener)
  37.  
  38.        
  39.         #opener.open(request)
  40.         request = urllib2.Request(self._login_url,self._connect_info['post_data'])
  41.         conn = opener.open(request)
  42.         if(conn.geturl() == self._login_url):
  43.             self._connect_info['cookie'].save(self._data['cookie_file_path'])
  44.         else:
  45.             pass
  46.         #根据js中的链接连接登录
  47.         partner = re.compile(self._re)
  48.         match = partner.findall(conn.read())
  49.        
  50.         for item in match:
  51.             opener.open(item)
  52.              
  53.        
  54.         #登录成功开始领豆
  55.         url = 'http://down.51cto.com/download.php'
  56.         data = {'do':'getfreecredits','t':random.random()}
  57.         opener.open(url, urllib.urlencode(data))
  58.         #html = opener.open('http://down.51cto.com/')
  59.        
  60.         #领无忧币
  61.         url = 'http://home.51cto.com/index.php'
  62.         data = {'s':'/Home/toSign'}
  63.         opener.open(url, urllib.urlencode(data))
  64.  
  65. if __name__ == '__main__':
  66.     login_51cto = Login()
  67.     login_51cto.open()
  68.        
  69.        
  70.        
  71.    
  72. #//python/1182

回复 "51CTO自动登录,领下载豆,领无忧币"

这儿你可以回复上面这条便签

captcha