1. 程式人生 > >基於Python輕度使用Chrome Headless(谷歌瀏覽器無頭模式)

基於Python輕度使用Chrome Headless(谷歌瀏覽器無頭模式)

簡單demo如下

# coding: utf-8
from selenium import webdriver


chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
client = webdriver.Chrome(chrome_options=chrome_options)
# 如果沒有把chromedriver加入到PATH中,就需要指明路徑 executable_path='/home/chromedriver'
client.get("https://www.aliyun.com/jiaocheng/124644.html") content = client.page_source print(content) client.quit()

如果content打印出正確內容,說明程式執行成功