一、无头模式
from selenium import webdriver
from import Options # => 引入Chrome的配置
import time
# 配置
ch_options = Options()
ch_options.add_argument("--headless") # => 为Chrome配置无头模式
# 在启动浏览器时加入配置
driver = (chrome_options=ch_options) # => 注意这里的参数
('')
driver.find_element_by_id('kw').send_keys('测试')
driver.find_element_by_id('su').click()
(2)
# 只有截图才能看到效果咯
driver.save_screenshot('./')
()
二、防止被检测
防止网站识别Selenium代码
from import Chrome
from import ChromeOptions
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
bro = Chrome(options=option)
url = "" # 首页
("/")
bro.implicitly_wait(10)
本文参考链接:/wukai66/p/