fix: replaced deprecated pdfkit with weasyprint, remove pure newlines and links from pdf
This commit is contained in:
1 parent
9bd20bf1ae
commit
fc00034361
1 file changed
+10
-8
+10
-8
@@ -1,7 +1,7 @@
|
|||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import pdfkit
|
from weasyprint import HTML
|
||||||
|
|
||||||
class MLWerk:
|
class MLWerk:
|
||||||
class SubSite:
|
class SubSite:
|
||||||
@@ -31,22 +31,24 @@ class MLWerk:
|
|||||||
if limit != None and i > limit:
|
if limit != None and i > limit:
|
||||||
break
|
break
|
||||||
link = link.get('href')
|
link = link.get('href')
|
||||||
if not (link == None and ("#" in link or "/" in link)):
|
if not link == None and not ("#" in link or "/" in link):
|
||||||
self.subsites.append(self.SubSite(urllib.parse.urljoin(self.baseurl, link)))
|
self.subsites.append(self.SubSite(urllib.parse.urljoin(self.baseurl, link)))
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def concatsubsites(self):
|
def concatsubsites(self):
|
||||||
for subsite in self.subsites:
|
for subsite in self.subsites:
|
||||||
for element in subsite.soup.body:
|
for tag in subsite.soup.body:
|
||||||
self.soup.body.append(element)
|
if (tag != "\n" and tag.name != "a"):
|
||||||
|
self.soup.body.append(tag)
|
||||||
|
|
||||||
def genpdf(self, path):
|
def genpdf(self, path):
|
||||||
pdfkit.from_string(str(self.soup), path, options={"enable-local-file-access": ""})
|
HTML(string=str(self.soup)).write_pdf(path)
|
||||||
|
|
||||||
def text2pdf(self, path):
|
def text2pdf(self, path, dry=False):
|
||||||
print("gettings subsites")
|
print("gettings subsites")
|
||||||
self.getsubsites
|
self.getsubsites()
|
||||||
print("concatting subsites")
|
print("concatting subsites")
|
||||||
self.concatsubsites
|
self.concatsubsites()
|
||||||
|
if not dry:
|
||||||
print("generating pdf")
|
print("generating pdf")
|
||||||
self.genpdf(path)
|
self.genpdf(path)
|
||||||
Reference in new issue
Block a user