problem description
write a Flask app, home page to display a form, then enter the conditions, submit, get N eligible news headlines from a fixed site, and then use pdfkit"s from_url to convert these pages into PDF. What I"m thinking about now is how to generate these pdf in memory and package them into a file for download?
related codes
/ / Please paste the code text below (do not replace the code with pictures)
txt = "./1.html"
with open(txt, "w", encoding="utf-8") as f:
f.write(responseRes.text)
file1 = open("1.html", "r", encoding="utf-8")
soup = BeautifulSoup(file1, "lxml")
memory_file = BytesIO()
with zipfile.ZipFile(memory_file, "w", zipfile.ZIP_DEFLATED) as zf:
for i in soup.find_all("a", class_="black"):
zf = pdfkit.from_url(["http://XXX.XXX.XXX" + i["href"]], False)
memory_file.seek(0)
rv = send_file(zf, as_attachment=True, attachment_filename="filename.zip")
return rv
what result do you expect? What is the error message actually seen?
expect the browser to download a zip file directly, but the browser returns a zip file of 0kb. How to implement it?