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)