新的一年剛開始,百度又有更新了。今天早上剛起床,開始了今天的學習之路。返現(xiàn)了一個有趣的事,和大家分享解決一下。
Chrome驅(qū)動打開百度時發(fā)現(xiàn)需要進行安全驗證。而且看到驗證的方式還特別新奇,如下圖需要圖片方正。
解決方法:可以通過隱藏WebDriver提示條和自動化擴展信息來跳過驗證。文章來源:http://www.zghlxwxcb.cn/news/detail-403879.html
from selenium import webdriver from selenium.webdriver import ChromeOptions
option=ChromeOptions() option.add_experimental_option('excludeSwitches',['enable-automation']) option.add_experimental_option('useAutomationExtension',False) brw=webdriver.Chrome(options=option) brw.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",{'source':'Object.defineProperty(navigator,"webdriver",{get:()=>undefind})'}) brw.get("http://www.baidu.com")
注:學習之路永無止境,代碼借鑒了爬蟲相關(guān)的書籍。文章來源地址http://www.zghlxwxcb.cn/news/detail-403879.html
到了這里,關(guān)于2022-爬蟲-Selenium-百度安全驗證的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!