如何在 Windows 10 上的 Chrome 60 中使用 Headless Chrome? [英] How do I use Headless Chrome in Chrome 60 on Windows 10?

查看:37
本文介绍了如何在 Windows 10 上的 Chrome 60 中使用 Headless Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看以下关于 Headless Chrome 的文章:
https://developers.google.com/web/updates/2017/04/headless-chrome

I've been looking at the following article about Headless Chrome:
https://developers.google.com/web/updates/2017/04/headless-chrome

我刚刚将 Windows 10 上的 Chrome 升级到版本 60,但是当我从命令行运行以下任一命令时,似乎什么也没发生:

I just upgraded Chrome on Windows 10 to version 60, but when I run either of the following commands from the command line, nothing seems to happen:

chrome --headless --disable-gpu --dump-dom https://www.google.com/
chrome --headless --disable-gpu --print-to-pdf https://www.google.com/

我正在从以下路径(Windows 上 Chrome 的默认安装路径)运行所有这些命令:

And I'm running all of these commands from the following path (the default installation path for Chrome on Windows):

C:Program Files (x86)GoogleChromeApplication

当我运行命令时,似乎有一些东西在处理一秒钟,但我实际上什么也没看到.我做错了什么?
谢谢.

When I run the commands, something seems to process for a second, but I don't actually see anything. What am I doing wrong?
Thanks.

正如 Mark Rajcok 所指出的,如果您将 --enable-logging 添加到 --dump-dom 命令,它会起作用.此外,--print-to-pdf 命令在 Chrome 61.0.3163.79 中也可以正常工作,但您可能必须为输出文件指定不同的路径才能获得必要的权限保存它.

As noted by Mark Rajcok, if you add --enable-logging to the --dump-dom command, it works. Also, the --print-to-pdf command works as well in Chrome 61.0.3163.79, but you'll probably have to specify a different path for the output file in order to have the necessary permissions to save it.

因此,以下两个命令对我有用:

As such, the following two commands worked for me:

"C:Program Files (x86)GoogleChromeApplicationchrome" --headless --disable-gpu --enable-logging --dump-dom https://www.google.com/
"C:Program Files (x86)GoogleChromeApplicationchrome" --headless --disable-gpu --print-to-pdf=D:output.pdf https://www.google.com/

我想下一步是能够通过带有 DOM 选择器之类的 PhantomJS 之类的转储 DOM,但我想这是一个单独的问题.

I guess the next step is being able to step through the dumped DOM like PhantomJS with DOM selectors and whatnot, but I suppose that's a separate question.

编辑#2:

不管怎样,我最近遇到了一个用于无头 Chrome 的 Node API,名为 Puppeteer (https://github.com/GoogleChrome/puppeteer),它非常易于使用并提供无头 Chrome 的所有功能.如果您正在寻找一种使用 Headless Chrome 的简单方法,我强烈推荐它.

For what it's worth, I recently came across a Node API for Headless Chrome called Puppeteer (https://github.com/GoogleChrome/puppeteer), which is really easy to use and delivers all the power of Headless Chrome. If you're looking for an easy way to use Headless Chrome, I highly recommend it.

推荐答案

这对我有用:

start chrome --enable-logging --headless --disable-gpu --print-to-pdf=c:miscoutput.pdf https://www.google.com/

...但仅使用start chrome"和--enable-logging"并指定路径(用于 pdf) - 并且如果文件夹misc"存在于 c 目录中.

... but only with "start chrome" and "--enable-logging" and with a path (for the pdf) specified - and if the folder "misc" exists on the c-directory.

添加:... pdf 的路径 - 上面的c:misc" - 当然可以替换为任何其他文件夹/目录.

Addition: ... the path for the pdf - "c:misc" above - can of course be replaced with any other folder/dir.

这篇关于如何在 Windows 10 上的 Chrome 60 中使用 Headless Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆