zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python3 selenium chrome headless 无界面浏览器

Python3Chrome浏览器 界面 selenium Headless
2023-09-14 09:16:05 时间

macOS 谷哥无界面浏览器 selenium

1,无界面谷哥浏览器

$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G65
$ pip3 show selenium
Name: selenium
Version: 3.141.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: urllib3
Required-by: 
$ chromedriver -v
ChromeDriver 2.43.600229

2,无界面浏览器测试

#! /usr/local/bin/python3
"""
chrome 谷歌无界面浏览器
"""

from selenium import webdriver


option = webdriver.ChromeOptions()
option.add_argument("headless")
driver = webdriver.Chrome( chrome_options = option )
url = "https://www.baidu.com"
driver.get(url)
print (driver.title)

#print ( driver.page_source)
driver.close()
driver.quit()

参考:

  1. selenium操作无界面chrome浏览器
  2. selenium+python自动化87-Chrome浏览器静默模式启动(headless)
  3. macOS+python3+selenium+chromedriver