700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python模拟登录163邮箱_python模拟登录网易邮箱-阿里云开发者社区

python模拟登录163邮箱_python模拟登录网易邮箱-阿里云开发者社区

时间:2019-11-14 05:39:43

相关推荐

python模拟登录163邮箱_python模拟登录网易邮箱-阿里云开发者社区

python模拟登录网易邮箱

#coding:utf-8

import urllib2,urllib

import cookielib

from bs4 import BeautifulSoup

#设置代理IP

proxy_support = urllib2.ProxyHandler({'http':'120.197.234.164:80'})

#设置cookie

cookie_support = urllib2.HTTPCookieProcessor(cookielib.LWPCookieJar())

opener = urllib2.build_opener(proxy_support,cookie_support,urllib2.HTTPHandler)

urllib2.install_opener(opener)

#开始的URL

#hosturl = ""

hosturl = "/"

#接受表单数据的URL

#posturl = "/ajaxLogin/login"

posturl = "/entry/cgi/ntesdoor?df=mail163_letter&from=web&funcid=loginone&iframe=1&language=-1&passtype=1&product=mail163&net=e&style=-1&race=118_35_39_bj&uid=Thinkgamer@"

#发送表单数据

postdata = urllib.urlencode(

{

"username":"xxxxxxxxxxx",

"password":"xxxxxxxxxxxxxxx"

}

)

#设置表头

headers = {

#'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/0101 Firefox/40.0/',

#'Referer':'/'

'User-Agent':"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/0101 Firefox/41.0",

'Referer':'/'

}

#生成HTTP请求

req =urllib2.Request(

url = posturl,

data = postdata,

headers = headers

)

print req

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

print page

listvalue = page.split(";")

url = listvalue[0].split("op.location.href = ")[1]

href = url[1:-1]

print href

soup = BeautifulSoup(urllib2.urlopen(href))

print soup.title

推荐一篇不错的文章:/python-network-application/observer-spider

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。