chrome headless (headless) mode

chrome headless (headless) mode
call phantomjs browser with selenium way almost any website crawling, but compared with calls chrome, phantomjs stability is not enough. If it can not display interface chrome, silently running in the background, all the better.

chome59 above the corresponding support headless Chromedriver be used as follows:

from selenium import  webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome('E:/chromedriver.exe',chrome_options = chrome_options)
driver.get('https://www.baidu.com')

If you are using version 59 or less, you can use pyvirtualdisplay create a virtual interface, and then run chromedriver:

from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=False,size=(1024,768))
display.start()
driver = webdriver.Chrome('E:/chromedriver.exe',chrome_options = chrome_options)
driver.get('https://www.baidu.com')

Chrome versions corresponding chromedriver see: selenium and chrome version of chromedriver map (updated to v2.40)

Guess you like

Origin www.cnblogs.com/hl-2030/p/12063550.html