英文:
chrome.exe --headless not working at all anyways
问题
我正在尝试从PowerShell(提升权限)运行以下命令,但命令立即退出,没有任何错误或错误文件。它也不会创建截图。为什么?我现在该怎么办?谢谢
chrome.exe --user-data-dir="B:\chrome" --headless --disable-gpu --screenshot="B:\chrome\_screenshots" https://example.com/
英文:
I'm trying to run chrome.exe --user-data-dir="B:\chrome" --headless --disable-gpu --screenshot="B:\chrome\_screenshots" https://example.com/
from PowerShell (elevated), the command exits itself immediately without any error or error file. It doesn't create the screenshot either. Why? What can I do now? Thanks
答案1
得分: 0
尝试指定一个窗口大小
&"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --screenshot="$ENV:USERPROFILE\Desktop\chrome.png" --window-size=1980,960 "https://stackoverflow.com"
这将在您的桌面上创建一个名为"chrome.png"的1980x960 png文件。
另外,您可能会有大量后台运行的chrome.exe进程,请使用任务管理器或其他方式关闭它们。
还有!
如果您想要正确地自动化这些截图,
请查看Puppeteer或Selenium,以及CDP。
英文:
Try specifying a window size
&"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --screenshot="$ENV:USERPROFILE\Desktop\chrome.png" --window-size=1980,960 "https://stackoverflow.com"
This will create a 1980x960 png on your desktop called "chrome.png"
Also, you probably have tons of chrome.exe processes running in the background, close them with task manager or something.
Also!
If you're looking into properly automating these screenshots,
have a look at Puppeteer or Selenium, and CDP in general.
答案2
得分: 0
正确做法是你应该指定一个文件,而不是一个目录(目录不会创建任何东西)。
不正确的写法:
--screenshot="B:\chrome\_screenshots"
正确的写法:
--screenshot="B:\chrome\_screenshots\chrome.png"
英文:
So the trick was that you should specify a file, not a directory (which doesn't create anything).
Incorrect:
--screenshot="B:\chrome\_screenshots"
Correct:
--screenshot="B:\chrome\_screenshots\chrome.png"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论