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