selenium實現無可視化瀏覽器以及反檢測


現在很多網站添加了檢測selenium的工具,但selenium也有反檢測的類,就是selenium中的ChromeOptions類

代碼如下:

from selenium import webdriver
import time
# 實現無可視化界面
from selenium.webdriver.chrome.options import Options
# 實現規避檢測
from selenium.webdriver import ChromeOptions

# 實現無可視化界面
chrome_options=Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# 實現規避檢測
option=ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-automation'])

# 無頭瀏覽器 + 反檢測
wd=webdriver.Chrome(executable_path='./chromedriver.exe',chrome_options=chrome_options,option=option)
wd.get('https://www.baidu.com')
print(wd.page_source)
time.sleep(5)
wd.quit()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM