python读取163邮件内容_python登陆163获取邮件和通讯录列表方法

#-*- coding:UTF-8 -*-

import urllib,urllib2,cookielib

import xml.etree.ElementTree as etree #xml解析类

class Login163:

#伪装browser

header = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}

username = ''

passwd = ''

cookie = None #cookie对象

cookiefile = './cookies.dat' #cookie临时存放地

user = ''

def __init__(self,username,passwd):

self.username = username

self.passwd = passwd

#cookie设置

self.cookie = cookielib.LWPCookieJar() #自定义cookie存放

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))

urllib2.install_opener(opener)

#登陆

def login(self):

#请求参数设置

postdata = {

'username':self.username,

'password':self.passwd,

'type':1

}

postdata = urllib.urlencode(postdata)

#发起请求

req = urllib2.Request(

url='http://reg.163.com/logins.jsp?type=1&product=mail163&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D1',

data= postdata,#请求数据

headers = self.header #请求头

)

result = urllib2.urlopen(req).read()

result = str(result)

#print result

self.user = self.username.split('@')[0]

self.cookie.save(self.cookiefile)#保存cookie

if '登录成功,正在跳转...' in result:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值