diff --git a/README.md b/README.md index dc6828f..603ae5e 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,14 @@ And also fixes any relative links to be absolute. ## Usage +Install dependencies first of course + +```sh +pip install -r requirements.txt +``` + +Then run it: + ```sh python3 owug.py 'https://example.com' 'out.html' ``` diff --git a/owug.py b/owug.py index 7efb86f..b783b8a 100644 --- a/owug.py +++ b/owug.py @@ -1,7 +1,7 @@ import sys from bs4 import BeautifulSoup import requests -import base64 +from pybase64 import b64encode_as_string def absolute_url(url, base_domain): @@ -33,7 +33,7 @@ for favicon in favicons: url = absolute_url(favicon.attrs['href'], domain_thing) mime_type = requests.head(url).headers['Content-Type'] - as_base64 = base64.b64encode(requests.get(url).content).decode() + as_base64 = b64encode_as_string(requests.get(url).content) new_url = f'data:{mime_type};base64,{as_base64}' favicon.attrs['href'] = new_url @@ -43,7 +43,7 @@ imgs = soup.find_all('img') for item in imgs: url = absolute_url(item.attrs['src'], domain_thing) mime_type = requests.head(url).headers['Content-Type'] - as_base64 = base64.b64encode(requests.get(url).content).decode() + as_base64 = b64encode_as_string(requests.get(url).content) new_url = f'data:{mime_type};base64,{as_base64}' item.attrs['src'] = new_url diff --git a/requirements.txt b/requirements.txt index 3836f55..e522070 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ bs4 requests -html5lib \ No newline at end of file +html5lib +pybase64 \ No newline at end of file