Created
December 3, 2021 03:47
-
-
Save tudoanh/cfbbf57be2b21afe64ff3a53f7f3f540 to your computer and use it in GitHub Desktop.
Download web to pdf using google-chrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import sys | |
import requests | |
import bs4 | |
from slugify import slugify | |
from rich.console import Console | |
console = Console() | |
url = sys.argv[1] | |
r = requests.get(url) | |
html = bs4.BeautifulSoup(r.text, features="lxml") | |
title = html.title.text | |
file_name = f"{slugify(title)}.pdf" | |
subprocess.run(["google-chrome", "--headless", f"--print-to-pdf={file_name}", url]) | |
console.print(f"Downloaded from [i]{url}[/i] to [bold green]{file_name}[/bold green]") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pip install requests beautifulsoup4 python-slugify rich
chmod a+x web_to_pdf.py