码迷,mamicode.com
首页 > 编程语言 > 详细

python3登录网页(163邮箱)实例

时间:2014-04-28 07:50:10      阅读:748      评论:0      收藏:0      [点我收藏+]

标签:com   http   code   type   log   user   int   window   word   odi   res   

# -*- coding: utf-8 -*-

 

import urllib
import http.cookiejar as cookielib
import urllib.request as urllib2

 

#创建cookie
cookie = cookielib.CookieJar()
cookieProc = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(cookieProc)
urllib2.install_opener(opener)

 

#登录网页
data = {‘username‘:‘xxx@163.com‘,‘password‘:‘xxxxxx‘,‘type‘:1}
post_data = urllib.urlencode(data).encode(‘UTF-8‘)
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‘}
request = urllib2.Request(url = ‘http://reg.163.com/logins.jsp‘,data = post_data,headers = header)
res = urllib2.urlopen(request).read().decde(‘UTF-8‘)

 

#如果上面代码没有install_opener(),则这里可用:opener.open(req).read()方法来获取内容。
print(res)

python3登录网页(163邮箱)实例,码迷,mamicode.com

python3登录网页(163邮箱)实例

标签:com   http   code   type   log   user   int   window   word   odi   res   

原文地址:http://www.cnblogs.com/doudongchun/p/3694836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!