在Python中用Request庫類比登入(一):字幕庫(無加密,無驗證碼),pythonrequest

來源:互聯網
上載者:User

在Python中用Request庫類比登入(一):字幕庫(無加密,無驗證碼),pythonrequest

如此簡單(不安全)的登入表單已經不多見了。字幕庫的登入表單如下所示,其中省去了無關緊要的內容:

1 <form class="login-form" action="/User/login.html" method="post">2     <input type="hidden" name="referer" value="http://www.zimuku.net/">3     <input type="text" id="inputEmail" datatype="*1-16" value="" name="username">4     <input type="password" id="inputPassword" datatype="*6-20" name="password">5     <input type="checkbox" name="isremember" value="1" checked="">6     <button type="submit" class="btn submit-btn">登 陸</button>7 </form>  

通過抓包分析,可以發現使用者名稱和密碼都沒有被加密:

直接使用POST來類比登入:

 1 import requests 2 from bs4 import BeautifulSoup 3  4 url='http://www.zimuku.net/User/login.html' 5 data={'referer':'','username':'***','password':'***','isremember':'1'} 6  7 #建立會話 8 session=requests.session() 9 #類比登入10 r=session.post(url,data=data)11 #解析頁面12 bs=BeautifulSoup(r.text,'lxml')13 14 print(bs.body.text) #登入成功!頁面自動 跳轉 等待時間: 1

成功登入,分析返回頁面中的js代碼,發現有:

href = document.getElementById('href').href;location.href = href;

說明要跳轉到的頁面在id為href的超連結中:

<a id="href" href="/User/index.html">跳轉</a>

擷取要跳轉到的頁面,然後嘗試開啟新頁面時登入狀態能否被保持:

1 href='http://www.zimuku.net'+bs.find(id='href').attrs['href']2 r2=ss.get(href)3 print(BeautifulSoup(r2.text,'lxml').title.text)#首頁 - 使用者中心 - 字幕庫(zimuku.net)

列印出了“首頁 - 使用者中心”字樣,成功保持登入狀態。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.