Python自动登录126邮箱的方法

yipeiwu_com7年前Python基础

本文实例讲述了Python自动登录126邮箱的方法。分享给大家供大家参考。具体实现方法如下:

import sys, urllib2, urllib,cookielib
import re
cookie = cookielib.LWPCookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
urllib2.install_opener(opener)
url='http://entry.mail.126.com/cgi/login?hid=10010102&lightweight=1&language=0&style=11'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
values = {'bCookie' : '',
  'domain' : '126.com',
  'enter.x' : '登 录',
  'language':'0',
  'pass':'#####',
  'style':'11',
  'user':'guijia8427'}
data = urllib.urlencode(values)
req = urllib2.Request(url, data ,headers)
response = urllib2.urlopen(req)
the_page = response.read()
sor= re.compile(r'sid=(.+)&funcid')
s=sor.findall(the_page)
url2='http://tg1a3.mail.126.com/coremail/fcg/ldapapp?funcid=mails&sid='+s[0]+'&fid=1'
g=opener.open(url2)
data2=g.read()
file=open('126.html','w')
file.write(data2)
file.close()

希望本文所述对大家的Python程序设计有所帮助。

相关文章

使用Python的判断语句模拟三目运算

下面说的和三目运算有点相似,但又不一样,实在不知道该如何拟定标题,先就是这个标题吧,大家都知道python中没有三目运算,但是and/or有点类似三目运算: and/or 单独使用表示逻...

Python3.5以上版本lxml导入etree报错的解决方案

Python3.5以上版本lxml导入etree报错的解决方案

在python中安装了lxml-4.2.1,在使用时发现导入etree时IDE中报错Unresolved reference 其实发现,不影响使用,可以正常运行,对于我这种要刨根问底的...

python 快速排序代码

复制代码 代码如下: def quick_sort(ls): return [] if ls == [] else quick_sort([y for y in ls[1:] if y...

python生成密码字典的方法

python生成密码字典的方法

这里我使用的是python27 主要用的是我之前博文里提到的itertools循环迭代的模块,用这个模块可以省不少事 首先要调用itertools import itertools...

Python+django实现文件上传

1、文件上传(input标签)  (1)html代码(form表单用post方法提交) <input class="btn btn-primary col-md-1"...