From 1f431d5d00bb13a1e7aabf1cb9f0de4bd7a2227c Mon Sep 17 00:00:00 2001 From: Phantop Date: Wed, 31 Jan 2024 10:51:59 -0500 Subject: [PATCH] bin: script to get page html after js render --- bin/qtcurl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bin/qtcurl diff --git a/bin/qtcurl b/bin/qtcurl new file mode 100755 index 0000000..5a822fa --- /dev/null +++ b/bin/qtcurl @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import sys + +from PyQt6.QtCore import QUrl +from PyQt6.QtWidgets import QApplication +from PyQt6.QtWebEngineWidgets import QWebEngineView + +def save_html(html): + if len(sys.argv) > 2 and sys.argv[2] == '-f': + filename = sys.argv[3] if len(sys.argv) > 3 else "dump.html" + with open(filename, 'w') as f: + f.write(html) + else: + print(html) + sys.exit() + +if __name__ == '__main__': + app = QApplication(sys.argv) + wv = QWebEngineView() + + wv.loadFinished.connect(lambda: wv.page().toHtml(save_html)) + wv.load(QUrl.fromUserInput(sys.argv[1])) + app.exec()