用python登錄Dr.com思路以及代碼分享
前提:isp得支持web登錄的方式。
說明:每個ISP的登錄頁面不一樣,不過我估計算法都是一樣的,于是解決方案應(yīng)該也是相似的,只是表單的key可能不太一樣。
首先,分析登錄頁面。
頁面head鑲嵌了<script>標(biāo)簽,所有的提交相關(guān)的腳本都在這里。頁面關(guān)鍵部分是兩個表單:f1和f0。整個f0是看不見的,但是點(diǎn)擊f1的提交時,會直接調(diào)用f0的提交而不是提交自己。表單的table布局就不吐槽了...
部分HTML
<form name="f1" method="post" action="" onsubmit="return ee()"> <table border="0" width="100%" cellspacing="1" cellpadding="0" height="100%" class="f1"> ... <tr> <td height="34" width="35%" align="right">賬號 Account </td><td height="34" width="64%"> <input name="DDDDD" type="text" maxlength="26" class="input-border"></td> </tr> <tr> <td height="32" width="35%" align="right">密碼 Password </td><td height="32" width="64%"> <input name="upass" type="password" maxlength="16" class="input-border"></td> </tr> <tr> <td height="57" width="35%"> </td><td height="57" width="64%"> <input type="submit" name="0MKKey" value="" onclick="cc(0)" class="login-b"> <input type="submit" name="" value="" onclick="reset();return false;"></td> </tr> ... </form>
這里可以看見,點(diǎn)擊submit的時候,調(diào)用cc(0),提交的時候調(diào)用ee()函數(shù)
部分js:
function cc(ss) { f0.R1.value = ss; } function ee() { if (f1.DDDDD.value == "") { alert("請輸入您的賬號 Please enter your account account number"); return false; } f0.DDDDD.value = f1.DDDDD.value if (ps == 0) { f0.upass.value = xproc1(f1.upass.value); } else { tmpchar = pid + f1.upass.value + calg; f0.upass.value = calcMD5(tmpchar) + calg + pid; f0.R2.value = 1; } document.f0.submit(); return false; }
顯然,點(diǎn)擊提交后,會對f0進(jìn)行一系列賦值,如果沒有問題就會提交f0
f0:
<form name="f0" method="post" action=""><input type="hidden" name="DDDDD" value="0"><input type="hidden" name="upass" value="0"> <input type="hidden" name="R1" value="0"><input type="hidden" name="R2" value="0"><input type="hidden" name="para" value="00"> <input type="hidden" name="0MKKey" value="123456"> </form>
參考js里的內(nèi)容,用python的dict表示f0的話有如下的偽代碼:
f0={} f0["DDDDD"] = f1['DDDD'] f0["upass"] = calcMD5(pid + f1['upass'] + calg) + calg + pid; f0["R1"] = ss f0["R2"] = 1 f0["para"] = 00 f0["0MKKey"] = 123456
其中 ss、pid、calg都是常量,f1['DDDD']、f1['upass']分別是用戶輸入的用戶名和密碼字符串
關(guān)鍵在于calcMD5的算法。
從函數(shù)名和函數(shù)本身來看,這個函數(shù)是MD5的一種實(shí)現(xiàn)。然而對js代碼進(jìn)行移植的過程中出現(xiàn)了一些問題:js和python的移位操作表現(xiàn)不同。
既然整個f0['upass']字段除了用戶輸入的密碼以外,其它都是常量,完全可以用js計算出f0['upass'],python中只要保存這個字符串就行了。
檢查cookies發(fā)現(xiàn)整個網(wǎng)頁沒有使用cookies。
登錄后跳轉(zhuǎn)到登出頁面,分析登出頁面發(fā)現(xiàn),登出只需要訪問某個特定的網(wǎng)頁就行了。
于是整個思路很簡單,pos登錄服務(wù)器實(shí)現(xiàn)登錄,get指定網(wǎng)頁登出。實(shí)現(xiàn)代碼如下:
import sys from urllib import urlencode from urllib2 import urlopen username = "s10********" upass = "6696a3***********************************" LOGIN = "http://202.1**.***.***/" LOGOUT = "http://202.1**.***.***/F.htm" def post(url, data=None): if data: data = urlencode(data) response = urlopen(url, data) return response.read() def login(): data={} data["DDDDD"] = username data["upass"] = upass data["R1"] = 0 data["R2"] = 1 data["para"] = 00 data["0MKKey"] = 123456 post(LOGIN, data) pass def logout(): post(LOGOUT) def main(argv): if argv[0] in ('login','in','i'): login() elif argv[0] in ('logout','out','o'): logout() pass pass if __name__ == '__main__': main(sys.argv[1:]);
- python使用xauth方式登錄飯否網(wǎng)然后發(fā)消息
- python3模擬百度登錄并實(shí)現(xiàn)百度貼吧簽到示例分享(百度貼吧自動簽到)
- python使用rsa加密算法模塊模擬新浪微博登錄
- python實(shí)現(xiàn)人人網(wǎng)登錄示例分享
- python模擬登錄百度代碼分享(獲取百度貼吧等級)
- python模擬登錄百度貼吧(百度貼吧登錄)實(shí)例
- Python(Tornado)模擬登錄小米搶手機(jī)
- 利用webqq協(xié)議使用python登錄qq發(fā)消息源碼參考
- Python 用戶登錄驗(yàn)證的小例子
- 使用python實(shí)現(xiàn)baidu hi自動登錄的代碼
- python登錄QQ郵箱發(fā)信的實(shí)現(xiàn)代碼
- python cookielib 登錄人人網(wǎng)的實(shí)現(xiàn)代碼
- ssh批量登錄并執(zhí)行命令的python實(shí)現(xiàn)代碼
- Python使用Socket(Https)Post登錄百度的實(shí)現(xiàn)代碼
- python遠(yuǎn)程登錄代碼
相關(guān)文章
Python實(shí)現(xiàn)爬取亞馬遜數(shù)據(jù)并打印出Excel文件操作示例
這篇文章主要介紹了Python實(shí)現(xiàn)爬取亞馬遜數(shù)據(jù)并打印出Excel文件操作,結(jié)合實(shí)例形式分析了Python針對亞馬遜圖書數(shù)據(jù)的爬取操作,以及數(shù)據(jù)打印輸出Excel相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-05-05深入解析Python設(shè)計模式編程中建造者模式的使用
這篇文章主要介紹了深入解析Python設(shè)計模式編程中建造者模式的使用,建造者模式的程序通常將所有細(xì)節(jié)都交由子類實(shí)現(xiàn),需要的朋友可以參考下2016-03-03Django配合python進(jìn)行requests請求的問題及解決方法
Python作為目前比較流行的編程語言,他內(nèi)置的Django框架就是一個很好的網(wǎng)絡(luò)框架,可以被用來搭建后端,和前端進(jìn)行交互,那么我們現(xiàn)在來學(xué)習(xí)一下,如何用Python本地進(jìn)行requests請求,并通過請求讓Django幫我們解決一些問題2022-06-06NumPy創(chuàng)建數(shù)組的多種方式實(shí)現(xiàn)
在使用NumPy時,通常需要先創(chuàng)建一個數(shù)組,然后再對這個數(shù)組進(jìn)行各種操,本文主要介紹了NumPy創(chuàng)建數(shù)組的多種方式實(shí)現(xiàn),具有一定的參考價值,感興趣的可以了解一下2023-06-06