bin: script to get page html after js render

This commit is contained in:
Phantop 2024-01-31 10:51:59 -05:00
parent 47a7a77085
commit 1f431d5d00
1 changed files with 23 additions and 0 deletions

23
bin/qtcurl Executable file
View File

@ -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()