shell - 使用带有 url 参数的 headless chrome

标签 shell ubuntu google-chrome-headless

我已经使用 apt 在我的 Ubuntu 20 VM 上安装了 Google Chrome。当我运行诸如

google-chrome-stable --headless --disable-gpu --print-to-pdf="/var/www/reports/report.pdf" --run-all-compositor-stages-before-draw /var/www/html/temp.html
一切正常,我得到了呈现的 html 页面的 pdf。
但是,如果我添加一些 url 参数,例如:
google-chrome-stable --headless --disable-gpu --print-to-pdf="/var/www/reports/report.pdf" --run-all-compositor-stages-before-draw /var/www/html/temp.html?foo=bar
然后生成的 PDF 为空白。它包含页眉和页脚,但没有其他内容。
首先,有没有其他人遇到过这个或者我做错了什么?也许这是在 headless chrome 中内置的不接受 url 参数?
我已经通过 Google 进行了搜索,但无法找到答案,因此非常感谢您提供任何帮助。
编辑:只是添加;我尝试使用反斜杠转义问号,但这也没有用。

最佳答案

您需要添加反斜杠 ( \ )在所有查询参数中。
我在这里发布示例,请看一下!

initial_html_file_path = /var/www/html/temp.html?foo=bar&foo2=bar2

converted_html_file_path = /var/www/html/temp.html\?foo\=bar\&foo2\=bar2

-> 最终脚本
google-chrome-stable --headless --disable-gpu --print-to-pdf="/var/www/reports/report.pdf" --run-all-compositor-stages-before-draw /var/www/html/temp.html\?foo\=bar\&foo2\=bar2

关于shell - 使用带有 url 参数的 headless chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68132639/

相关文章:

javascript - Puppeteer 等到页面完全加载

google-chrome - 使用 chrome --print-to-pdf --headless 太快地打印 html?

linux - 如何将剪切的输出写入文件

linux - shell 编程: How to use find in fish?

ubuntu - 在主机上安装目标库

node.js - 找不到用户 : Could not find user nodejs@sDatabase

运行多个 shell 命令并等待结果的 Python 脚本

linux - 如何在需要的每一行的开头放置逗号

python - 调整 crontab 作业时间

docker - 在 Docker 容器中从 Chrome-Headless 请求 webSocketDebuggerUrl