selenium
无可视化界面,下面是例子代码,通过设置参数option实现。
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options imprt Options
chrome_options=options()
chrome_options.add_argument('--headeless')
chrome_options.add_argument('--disable-gpu')
bro=webdriver.Chrome(executable_path='./chromedriver',chrome_options=chrome_options)
bro.get('https://www.baidu.com')
bro.quit()
有些网站检测selenium访问如何避免,代码例子如下:
from selenium.webdriver import ChromeOptions
option=ChromeOptions()
option.add_experimental_option('excludeswitches',['enable-automation'])
driver=webdriver.Chrome(executable_path='./chromedriver',options=option)
网友评论