How do I use Headless Chrome in Chrome 60 on Windows 10?

后端 未结 6 1080
一生所求
一生所求 2020-12-29 00:56

I\'ve been looking at the following article about Headless Chrome:
https://developers.google.com/web/updates/2017/04/headless-chrome

I just upgraded Chrome on Wi

6条回答
  •  抹茶落季
    2020-12-29 01:42

    With Chrome 61.0.3163.79, if I add --enable-logging then --dump-dom produces output:

    > "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --enable-logging --headless --disable-gpu --dump-dom https://www.chromestatus.com
    
    
    ...
    
    
    

    If you want to programatically control headless Chrome, here's one way to do it with Python3 and Selenium:

    In an Admin cmd window, install Selenium for Python:

    C:\Users\Mark> pip install -U selenium
    

    Download ChromeDriver v2.32 and extract it. I put the chromedriver.exe in C:\Users\Mark, which is where I put this headless.py Python script:

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument("headless")  # remove this line if you want to see the browser popup
    driver = webdriver.Chrome(chrome_options = options)
    driver.get('https://www.google.com/')
    print(driver.page_source)
    driver.quit()  # don't miss this, or chromedriver.exe will keep running!
    

    Run it in a normal cmd window:

    C:\Users\Mark> python headless.py
    
    

提交回复
热议问题