本文實例講述了Python實現(xiàn)模擬登錄網(wǎng)易郵箱的方法。分享給大家供大家參考,具體如下:
專注于為中小企業(yè)提供成都做網(wǎng)站、網(wǎng)站設(shè)計服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)鹿邑免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千余家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。#coding:utf-8 import urllib2,urllib import cookielib from bs4 import BeautifulSoup #設(shè)置代理IP proxy_support = urllib2.ProxyHandler({'http':'120.197.234.164:80'}) #設(shè)置cookie cookie_support = urllib2.HTTPCookieProcessor(cookielib.LWPCookieJar()) opener = urllib2.build_opener(proxy_support,cookie_support,urllib2.HTTPHandler) urllib2.install_opener(opener) #開始的URL #hosturl = "http://www.renren.com" hosturl = "http://mail.163.com/" #接受表單數(shù)據(jù)的URL #posturl = "http://www.renren.com/ajaxLogin/login" posturl = "https://mail.163.com/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@163.com" #發(fā)送表單數(shù)據(jù) postdata = urllib.urlencode( { "username":"xxxxxxxxxxx", "password":"xxxxxxxxxxxxxxx" } ) #設(shè)置表頭 headers = { #'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0/', #'Referer':'http://www.renren.com/' 'User-Agent':"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0", 'Referer':'http://mail.163.com/' } #生成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