日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

selenium:反反爬拖动验证码

發(fā)布時(shí)間:2024/9/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 selenium:反反爬拖动验证码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前言

  • springboot 2.0.0.RELEASE
  • selenium-java 3.9.1
  • chromedriver win32 2.33
  • chrome 62.0.3202.94
  • 你已經(jīng)可以編寫selenium程序爬一個(gè)沒有驗(yàn)證碼的網(wǎng)頁,但現(xiàn)在碰到了一個(gè)拖動(dòng)驗(yàn)證碼:https://cf.aliyun.com/nocaptcha

總結(jié)

經(jīng)過搜索、嘗試、再搜索、再嘗試…,終于發(fā)現(xiàn)需要使用兩項(xiàng)技術(shù)對(duì)selenium進(jìn)行反爬:

  • webdriver屬性
  • 特征$cdc_asdjflasutopfhvcZLmcfl_

通過js腳本提取webdriver屬性和特征$cdc_asdjflasutopfhvcZLmcfl_,將提取結(jié)果進(jìn)行編碼后發(fā)送給服務(wù)器。服務(wù)器發(fā)現(xiàn)是selenium爬蟲后,拒絕驗(yàn)證。

知道了反爬,則反反爬也就好辦了。逐項(xiàng)針對(duì)規(guī)避即可。
有大神已經(jīng)將步驟整理:https://blog.csdn.net/sdzhr/article/details/86714328
下面解惑一下:

webdriver屬性

Chrome從v63版本開始添加了webdriver屬性。只要通過selenium調(diào)用了瀏覽器便會(huì)將這個(gè)屬性設(shè)置為true。

當(dāng)服務(wù)器通過js腳本識(shí)別到webdriver屬性時(shí),會(huì)有如下現(xiàn)象:

  • 手工啟動(dòng)chrome,人工拖動(dòng)驗(yàn)證碼可以通過驗(yàn)證
  • 使用selenium啟動(dòng)chrome,人工拖動(dòng)驗(yàn)證碼無法通過驗(yàn)證
  • 使用selenium啟動(dòng)chrome,程序模擬拖動(dòng)驗(yàn)證碼無法通過驗(yàn)證

所以,避開webdriver屬性需要使用低于v63版本的Chrome(v62.0.3202.94版本測(cè)試通過)。

注:

  • 參考文章中提到的chrome 62.0.3202.62版本,未找到下載鏈接。
  • chrome和chromedriver之間是有對(duì)應(yīng)關(guān)系的,版本不匹配則無法使用。chrome和chromedriver之間的對(duì)應(yīng)關(guān)系。
  • 換用Firefox,也會(huì)有webdriver屬性。
  • 在瀏覽器的console控制臺(tái)中輸入navigator回車后,在輸出中會(huì)發(fā)現(xiàn)webdriver屬性,且值為true。

特征$cdc_asdjflasutopfhvcZLmcfl_

$cdc_asdjflasutopfhvcZLmcfl_是chromeDriver的特征之一。

chromeDriver會(huì)創(chuàng)建cdc_asdjflasutopfhvcZLmcfl_元素,并將該元素用于各種操作。比如,在使用findElement方法時(shí),會(huì)使用該元素。

當(dāng)服務(wù)器通過js腳本識(shí)別到特征“$cdc_asdjflasutopfhvcZLmcfl_”時(shí),會(huì)有如下現(xiàn)象:

  • 手工啟動(dòng)chrome,人工拖動(dòng)驗(yàn)證碼可以通過驗(yàn)證
  • 使用selenium啟動(dòng)chrome,人工拖動(dòng)驗(yàn)證碼可以通過驗(yàn)證
  • 使用selenium啟動(dòng)chrome,程序模擬拖動(dòng)驗(yàn)證碼無法通過驗(yàn)證。(原因即為上面所述)

避開webdriver屬性需要修改chromeDriver中的特征$cdc_asdjflasutopfhvcZLmcfl_。修改方法:

  • 通過文本編輯器打開chromedriver。linux下,通過vim chromedriver打開。windows下,通過notepad++打開chromedriver.exe。
  • 查找特征"cdc_",改為"chr_"。(刪掉幾個(gè)字符,則加幾個(gè)字符。不能改變var key = '$cdc_asdjflasutopfhvcZLmcfl_';key字符串的長度。否則,會(huì)導(dǎo)致chromedriver程序無法執(zhí)行)
  • 修改完成后保存。
  • Using Vim

    vim /path/to/chromedriver

    After running the line above, you’ll probably see a bunch of gibberish. Do the following:

  • Search for cdc_by typing /cdc_and pressing return.
  • Enable editing by pressing a.
  • Delete any amount of $cdc_lasutopfhvcZLmcfland replace what was deleted with an equal amount characters. If you don’t, chromedriverwill fail.
  • After you’re done editing, press esc.
    5.To save the changes and quit, type :wq!and press return.
  • If you don’t want to save the changes, but you want to quit, type :q!and press return.
  • You’re done.
  • Go to the altered chromedriver and double click on it. A terminal window should open up. If you don’t see killed in the output, you successfully altered the driver.

    springboot開發(fā)selenium程序

    springboot開發(fā)selenium非常簡單。可以參考:https://blog.csdn.net/l707268743/article/details/80942246

    參考

    https
    ?/blog.csdn.net/sdzhr/article/details/86714328
    https://gitee.com/bobozhangyx/java-crawler/blob/master/file/編譯后的chromedriver/
    https://stackoverflow.com/questions/33225947/can-a-website-detect-when-you-are-using-selenium-with-chromedriver
    https://blog.csdn.net/l707268743/article/details/80942246

    總結(jié)

    以上是生活随笔為你收集整理的selenium:反反爬拖动验证码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。