Python模擬登錄驗(yàn)證碼(代碼簡(jiǎn)單)
更新時(shí)間:2016年02月06日 16:51:27 投稿:mrr
這篇文章主要介紹了Python模擬登錄驗(yàn)證碼(代碼簡(jiǎn)單)的相關(guān)資料,需要的朋友可以參考下
廢話不多說(shuō)了,直接給大家貼代碼了。
import urllib
import urllib2
import cookielib
def getImg(picurl):
'''
request for random_code picture and cookie
'''
pic = opener.open(picurl).read()
with open('./verifyImg.jpg','wb') as emptyPic:
emptyPic.write(pic)
def verifyImg(picpath):
'''
TODO
'''
pass
def login(coo):
loginUrl = 'http://jwxt.wust.edu.cn/whkjdx/Logon.do?method=logon'
data = {'USERNAME':'*****', 'PASSWORD':'*****', 'RANDOMCODE':coo}
#encode the postData
postData = urllib.urlencode(data)
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
header = {'User-Agent':user_agent,'Referer':'http://jwxt.wust.edu.cn/whkjdx/framework/main.jsp'}
#generate a Request with url,postData headers and cookie
request = urllib2.Request(loginUrl, postData, headers = header)
#post data
content = opener.open(request)
#get html file
mainUrl = 'http://jwxt.wust.edu.cn/whkjdx/framework/main.jsp'
mainContent = opener.open(mainUrl).read()
print mainContent
if __name__ == '__main__':
cookie = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(cookie)
opener = urllib2.build_opener(handler)
picurl = 'http://jwxt.wust.edu.cn/whkjdx/verifycode.servlet'
getImg(picurl)
#verifyImg(picpath)
randomCode = raw_input('Plz input teh randomcode:')
login(randomCode)
以上代碼大家看起來(lái)很容易吧,有不明白的地方歡迎留言,我會(huì)在第一時(shí)間和大家取得聯(lián)系的。在此腳本之家小編祝大家新年快樂(lè)。
您可能感興趣的文章:
- Python完全識(shí)別驗(yàn)證碼自動(dòng)登錄實(shí)例詳解
- python自動(dòng)化實(shí)現(xiàn)登錄獲取圖片驗(yàn)證碼功能
- Python模擬登錄之滑塊驗(yàn)證碼的破解(實(shí)例代碼)
- python破解bilibili滑動(dòng)驗(yàn)證碼登錄功能
- Python使用selenium實(shí)現(xiàn)網(wǎng)頁(yè)用戶名 密碼 驗(yàn)證碼自動(dòng)登錄功能
- python自動(dòng)登錄12306并自動(dòng)點(diǎn)擊驗(yàn)證碼完成登錄的實(shí)現(xiàn)源代碼
- Python+Selenium+PIL+Tesseract自動(dòng)識(shí)別驗(yàn)證碼進(jìn)行一鍵登錄
- Python爬蟲模擬登錄帶驗(yàn)證碼網(wǎng)站
- Python3.7實(shí)現(xiàn)驗(yàn)證碼登錄方式代碼實(shí)例
相關(guān)文章
OpenCV實(shí)現(xiàn)對(duì)象跟蹤的方法
OpenCV 是一個(gè)很好的處理圖像和視頻的工具,本文主要介紹了OpenCV 進(jìn)行對(duì)象跟蹤,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10
PyQt5中多線程模塊QThread使用方法的實(shí)現(xiàn)
這篇文章主要介紹了PyQt5中多線程模塊QThread使用方法的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
Python設(shè)計(jì)模式之裝飾模式實(shí)例詳解
這篇文章主要介紹了Python設(shè)計(jì)模式之裝飾模式,結(jié)合實(shí)例形式詳細(xì)分析了裝飾模式的概念、原理并結(jié)合Python實(shí)例形式分析了裝飾模式的相關(guān)使用技巧,需要的朋友可以參考下2019-01-01
TensorFlow MNIST手寫數(shù)據(jù)集的實(shí)現(xiàn)方法
MNIST數(shù)據(jù)集中包含了各種各樣的手寫數(shù)字圖片,這篇文章主要介紹了TensorFlow MNIST手寫數(shù)據(jù)集的實(shí)現(xiàn)方法,需要的朋友可以參考下2020-02-02

