from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
# -------实现无可视化界面------- #
from selenium.webdriver.chrome.options import Options
# -------------------------实现规避检测------------------------- #
from selenium.webdriver import Chrome
from selenium.webdriver import ChromeOptions
# ---------------------实现无可视化界面的操作--------------------- #
chrome_Options = Options()
chrome_Options.add_argument('--headless')
chrome_Options.add_argument('--disable-gou')
# -------------实现规避检测------------- #
option = ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-autometion'])
# driver = Chrome(options=option)
# 如何实现让selenium规避被检测到的风险
bro = webdriver.Chrome(executable_path=r'C:Program FilesGoogleChromeApplicationchromedriver.exe',chrome_options=chrome_Options,options=option)
# 无可视化界面(无头浏览器)---phantomJs (对应谷歌里面的一个无头浏览器)注:已经停止更新和维护了
bro.get('https://baidu.com')
print(bro.page_source)
sleep(2)
bro.quit()