#!usr/bin/env python #-*- coding: utf-8 -*- import os import urllib2 import urllib import cookielib import re
Img_URL='http://www./api/captcha/' Login_URL='http://www./account/loginform' Class_URL='http://www./' def login(): cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) #get img img_req=urllib2.Request(Img_URL) img_response=opener.open(img_req) try: out=open('/home/ym/code','wb') #print img_response.read() out.write(img_response.read()) out.flush() out.close() print 'get code success' except IOError: print 'file wrong' #input code img_code=raw_input("please input code: ") print 'your code is %s'%img_code #login LoginData = { 'Email': '2027598917@qq.com', 'Password': 'hp201112701254', 'Captcha': img_code, 'Remember': 'true', 'Remember': 'false', 'Ver': 'True', 'AnonID': 'bf976050-bf60-4acd-b892-c3de2d0276de', 'Title':'' }; login_req = urllib2.Request(Login_URL, urllib.urlencode(LoginData)); login_req.add_header('User-Agent', "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"); login_response=opener.open(login_req) print 'login success' fout=open("/home/ym/tt.txt","w") fout.write(login_response.read()) fout.close() #load class info print 'load class' fout=open('/home/ym/t1.txt','w') fout.write(opener.open(Class_URL).read()) fout.close() if __name__=='__main__': login()
|