A
A
Ant1coder2020-08-26 11:58:53
Python
Ant1coder, 2020-08-26 11:58:53

Python - how to save a web page (Telegraph article) to PDF?

You need to save the web page, in this case the Telegraph article.
When I try

import pdfkit
pdfkit.from_url("https://telegra.ph/Statya-obrazec-08-26", "out.pdf")

I get a darkened pdf, which is inconvenient to read, but everything else is perfect.
When I try
from weasyprint import HTML
pdf = HTML('https://telegra.ph/Statya-obrazec-08-26').write_pdf()
f = open('out.pdf', 'wb')
f.write(pdf)
f.close()

I get a normal white pdf, with pictures, but there are krakozyabry - it doesn’t fit at all.

Trying through PyQt5 printers - no QtWebEngine in PyQt5. Delivered PyQtWebEngine - all the same it is not present anywhere.

What should I do in such despair?

UPD: Yuzayu Linux, Python 3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Guest007, 2020-09-03
@Guest007

Completely working solution. Works on the server too. https://wkhtmltopdf.org/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question