View Code
1 import urllib2,urllib 2 import sys 3 import cookielib 4 5 def login(): 6 headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1', 7 'Referer' : '******','Connection':'keep-alive'} 8 url='http://m.byr.cn/user/login' 9 postdata={'id':'cool15684','passwd':'6090960','save':'on'} 10 11 cj=cookielib.CookieJar() 12 opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 13 urllib2.install_opener(opener) 14 15 16 postdata = urllib.urlencode(postdata) 17 request = urllib2.Request(url=url,data=postdata,headers = headers) 18 19 respose = urllib2.urlopen(request) 20 21 22 text = respose.read() 23 24 type = sys.getfilesystemencoding() 25 #txt = txt.decode('gbk').encode(type) 26 f = open('WorkLife.html','w') 27 f.write(text) 28 f.close() 29 30 if __name__ == '__main__': 31 login()