<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] # 一 反爬措施 在需要登錄的頁面,用普通驗證碼攔截用戶,當手動獲取了改驗證碼并識別后,再次登錄,會發現驗證碼已經變了 因為驗證碼是點擊一次就變一次,所以獲取的驗證碼已經不是后面的驗證碼了 # 二 對抗措施 1. 使用session保持會話 2. 然后用該session去請求首頁 3. 獲取驗證碼地址并下載 4. 識別驗證碼并記錄 5. 獲取post請求的頁面和參數 6. 處理參數 7. 通過session,帶上參數登錄 # 三 借助session實現驗證碼登陸 ```python import requests from lxml import etree from chaojiying import Chaojiying_Client url='https://so.gushiwen.org/user/login.aspx?from=http://so.gushiwen.org/user/collect.aspx' headers={ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36' } # 1. 先實例化一個session對象,并帶上啊session請求網頁 res_s=requests.Session() pageinfo=res_s.get(url=url,headers=headers).text #2. 通過session,獲取網頁圖片 tree=etree.HTML(pageinfo) image_url='https://so.gushiwen.org/'+tree.xpath('//*[@id="imgCode"]/@src')[0] image_content=res_s.get(url=image_url,headers=headers).content with open('a.jpg','wb') as fp: fp.write(image_content) cjy=Chaojiying_Client('noah666', '68t.guCQ3uUmL8K', '904156') im = open('a.jpg', 'rb').read() image_code=cjy.PostPic(im, 1902)['pic_str'] # 3. 從tree對象中,解析post請求所需動態參數 VIEWSTATE=tree.xpath('//*[@id="__VIEWSTATE"]/@value')[0] VIEWSTATEGENERATOR=tree.xpath('//*[@id="__VIEWSTATEGENERATOR"]/@value')[0] # 4. 處理post請求網頁及參數 data={ '__VIEWSTATE': VIEWSTATE, '__VIEWSTATEGENERATOR': VIEWSTATEGENERATOR, 'from':'http://so.gushiwen.org/user/collect.aspx', 'email': 'www.zhangbowudi@qq.com', 'pwd': 'bobo328410948', 'code': image_code, 'denglu': '登錄' } url='https://so.gushiwen.org/user/login.aspx?from=http%3a%2f%2fso.gushiwen.org%2fuser%2fcollect.aspx' # 5. 模擬請求,并將結果保存 login=res_s.post(url=url,data=data,headers=headers).text with open('./gushiwenwang.html','w',encoding='utf-8') as fp: fp.write(login) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看