admin 管理员组

文章数量: 887021

2019独角兽企业重金招聘Python工程师标准>>>

selenium 不打开浏览器窗口模拟浏览器

  1. 安装 xvfb

xvfb: Xvfb is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.

sudo apt install xvfb

2 . 安装 pyvirtualdisplay

pyvirtualdisplay: pyvirtualdisplay is a python wrapper for Xvfb, Xephyr and Xvnc

sudo pip install pyvirtualdisplay

3 . 安装 chrome 浏览器

下载安装即可

4 . 安装 chromedriver

chromedriver: ChromeDriver is a separate executable that WebDriver uses to control Chrome. It is maintained by the Chromium team with help from WebDriver contributors. If you are unfamiliar with WebDriver, you should check out their own Getting Started page.

下载地址:chromedriver

5 . 示例 test1

import time
from pyvirtualdisplay import Display
from selenium import webdriver

url = "http://www.baidu"
with Display(backend="xvfb", size=(1440, 900)):
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get(url)
    driver.get_screenshot_as_file("test.png")
    time.sleep(3)
    driver.quit()

转载于:https://my.oschina/u/3826227/blog/1797056

本文标签: 浏览器 窗口 打开浏览器 selenium