支持HTML 5视频的无头浏览器?

11

我需要自动化截取HTML 5视频播放器页面及其缩略图的截图,但在查看了一些更受欢迎的无头浏览器(例如PhantomJS)后发现它们不支持HTML 5视频。

>phantomjs examples\features.js
Detected features (using Modernizr 2.0.6):

Supported:
  touch
  generatedcontent
  fontface
  flexbox
  canvas
  canvastext
  postmessage
  websqldatabase
  hashchange
  history
  draganddrop
  websockets
  rgba
  hsla
  multiplebgs
  backgroundsize
  borderimage
  borderradius
  boxshadow
  textshadow
  opacity
  cssanimations
  csscolumns
  cssgradients
  cssreflections
  csstransforms
  csstransitions
  localstorage
  sessionstorage
  webworkers
  applicationcache
  svg
  inlinesvg
  smil
  svgclippaths

Not supported:
  csstransforms3d
  webgl
  geolocation
  indexeddb
  video
  audio

请注意,HTML 5视频不受支持,那么哪个轻量级无界面浏览器支持HTML 5视频?


1
请查看此列表:https://github.com/dhamaniasad/HeadlessBrowsers - user5087998
2个回答

2

有一个解决方案,但它不是轻量级的。(虽然它很快)现在您可以使用无头选项运行Firefox。这里是一些代码,说明如何使用Selenium进行操作

options = new FirefoxOptions();
options.addArguments("--headless"); // This will make Firefox to run in headless mode.
System.setProperty("webdriver.gecko.driver", "lib/firefox/geckodriver.exe");
        FirefoxProfile profile = new FirefoxProfile();
        FirefoxBinary binary = new FirefoxBinary(new File("lib/firefox/firefox.exe"));
        options.setBinary(binary);
        options.setProfile(profile);
        driver = new FirefoxDriver(options);

或者您可以构建PanthomJS以支持HTML5。请按照此链接进行操作。


我在编译PhantomJS时未能成功添加video支持。 - Salem

1
基于文档SlimerJS可以播放HTML5视频和音频(并提供它们的屏幕截图):
由于SlimerJS在Firefox之上执行,因此它支持Firefox最近实现的所有HTML5标准,包括音频、视频、WebGL等。
SlimerJS中的网页呈现与Firefox中的呈现严格相同。
您可以访问caniuse.com查看Firefox支持的HTML5功能列表,并可以在SlimerJS加载的网页中使用这些功能。
也被认为支持Flash,但无法在屏幕截图中显示Flash内容:
如果安装了Flash插件,则SlimerJS可以加载Flash内容(尽管在进行屏幕截图时无法看到插件的呈现)。

从文档中得知:它目前还不支持原生无头模式。但是,在Linux下可以使用xvfb实现无头模式(但在MacOS上不行)。 - Andrei Volgin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接