网络爬虫(十七)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)

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