#_*_ coding:utf-8 _*_
#author:gaoqiang
import urllib,urllib2,cookielib
#使用cookie模块
def login_Tom(url="http://mail1.tom.com/webmail/login/loginService.action"):
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36'
,"Host":"mail1.tom.com","Referer":"http://web.mail.tom.com/webmail/login/index.action","Origin":"http://web.mail.tom.com"
,"Connection":"keep-alive","Upgrade-Insecure-Requests":"1"}
data={'username':'***@tom.com','password':'***',"from_domain":"web.mail.tom.com","jump":"1"}
data=urllib.urlencode(data)#使用urllib编码
req=urllib2.Request(url,data=data,headers=headers)
cookiejar=cookielib.CookieJar()
handler=urllib2.HTTPCookieProcessor(cookiejar=cookiejar)
opener = urllib2.build_opener(handler,urllib2.HTTPHandler(debuglevel=1))
s = opener.open(req)
html=s.read()
#s.close()
save_file("test.html",html)
print "="*20
print cookiejar._cookies
#保存文件
def save_file(filepath,txt=""):
files=open(filepath,"wb")
for line in txt:
files.write(line)
if __name__ == "__main__":
login_Tom()
print "finished"
#author:gaoqiang
import urllib,urllib2,cookielib
#使用cookie模块
def login_Tom(url="http://mail1.tom.com/webmail/login/loginService.action"):
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36'
,"Host":"mail1.tom.com","Referer":"http://web.mail.tom.com/webmail/login/index.action","Origin":"http://web.mail.tom.com"
,"Connection":"keep-alive","Upgrade-Insecure-Requests":"1"}
data={'username':'***@tom.com','password':'***',"from_domain":"web.mail.tom.com","jump":"1"}
data=urllib.urlencode(data)#使用urllib编码
req=urllib2.Request(url,data=data,headers=headers)
cookiejar=cookielib.CookieJar()
handler=urllib2.HTTPCookieProcessor(cookiejar=cookiejar)
opener = urllib2.build_opener(handler,urllib2.HTTPHandler(debuglevel=1))
s = opener.open(req)
html=s.read()
#s.close()
save_file("test.html",html)
print "="*20
print cookiejar._cookies
#保存文件
def save_file(filepath,txt=""):
files=open(filepath,"wb")
for line in txt:
files.write(line)
if __name__ == "__main__":
login_Tom()
print "finished"