admin 管理员组文章数量: 887021
2019独角兽企业重金招聘Python工程师标准>>>
selenium 不打开浏览器窗口模拟浏览器
- 安装 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 不打开浏览器窗口模拟浏览器 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1726856254h1040386.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论