aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/utils/utils.py b/utils/utils.py
index bf3d4fbe..a82c23e6 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -7,6 +7,9 @@ import time
import datetime
import dateutil.tz
+import bs4
+import urllib.parse
+
@contextmanager
def init_colorama():
@@ -34,3 +37,18 @@ def current_datetime():
"""
return datetime.datetime.fromtimestamp(round(time.time()),
dateutil.tz.tzlocal())
+
+
+def absolutify_links(soup, baseurl):
+ """Make links in an article absolute.
+
+ Parameters
+ ----------
+ soup : bs4.BeautifulSoup
+ baseurl : str
+
+ """
+ for tag in soup.find_all(lambda tag: tag.has_attr("href")):
+ tag["href"] = urllib.parse.urljoin(baseurl, tag["href"])
+ for tag in soup.find_all(lambda tag: tag.has_attr("src")):
+ tag["src"] = urllib.parse.urljoin(baseurl, tag["src"])