python爬虫学习之selenium_chrome handless的使用

目录

一、Chrome handless简介

二、Chrome handless的系统要求

三、Chrome handless的基本配置  (直接复制放在.py文件开头)

 四、Chrome handless 的应用

五、Chrome handless的封装


 

一、Chrome handless简介

Chrome handless 模式,Google 针对 Chrome 浏览器 59版 新增的一种模式,可以让你不打开 UI 界面的情况下使用 Chrome 浏览器,所以运行效果与 Chrome 保持完美一致。

二、Chrome handless的系统要求

1、Chrome 版本要求

     Unix/Linux 系统要求 chrome >= 59

     Windows 系统需要 chrome >= 60 

2、Python 版本 >= 3.6

3、Selenium 版本 >= 3.4.*

4、ChromeDriver 版本 >= 2.31

三、Chrome handless的基本配置  (直接复制放在.py文件开头)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options. add_argument('--headless')

#path是自己电脑的Chrome浏览器文件地址
path = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
chrome_options.binary_location = path

browser = webdriver.Chrome(options=chrome_options)

 四、Chrome handless 的应用

e.g.访问百度网站

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options. add_argument('--headless')

#path是自己电脑的Chrome浏览器文件地址
path = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
chrome_options.binary_location = path

browser = webdriver.Chrome(options=chrome_options)

url = 'https://www.baidu.com'

browser.get(url)

 注:chrome_options已经被options替代

五、Chrome handless的封装

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def common_browser():
    chrome_options = Options()
    chrome_options.add_argument('--headless')

    # path是自己电脑的Chrome浏览器文件地址
    path = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
    chrome_options.binary_location = path

    browser = webdriver.Chrome(options=chrome_options)
    return browser

注:使用时直接调用函数

browser = common_browser()

url = 'https://www.baidu.com'

browser.get(url)

 

相关推荐

  1. python爬虫学习selenium_chrome handless使用

    2024-01-31 06:04:02       50 阅读
  2. Python爬虫pyquery和parsel使用

    2024-01-31 06:04:02       35 阅读
  3. Python爬虫学习selenium库

    2024-01-31 06:04:02       59 阅读
  4. Python爬虫学习requests库

    2024-01-31 06:04:02       55 阅读
  5. Python爬虫学习requests库

    2024-01-31 06:04:02       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-31 06:04:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-31 06:04:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-31 06:04:02       87 阅读
  4. Python语言-面向对象

    2024-01-31 06:04:02       96 阅读

热门阅读

  1. Hive之set参数大全-22(完)

    2024-01-31 06:04:02       41 阅读
  2. Servlet基础之URL匹配规则

    2024-01-31 06:04:02       46 阅读
  3. 交换机 路由器 网卡 MAC

    2024-01-31 06:04:02       58 阅读
  4. Session

    Session

    2024-01-31 06:04:02      38 阅读
  5. C语言:计算任意年份及月份的天数

    2024-01-31 06:04:02       63 阅读