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()
posted @ 2020-09-12 11:06  君莫笑丶丶  阅读(792)  评论(0编辑  收藏  举报