網絡爬蟲(十七)selenium 無可視化界面

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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章