Skip to content

Instantly share code, notes, and snippets.

@kokimame
Created September 17, 2017 14:13
Show Gist options
  • Select an option

  • Save kokimame/46a3fd56296a9cc1acff6be8198faf78 to your computer and use it in GitHub Desktop.

Select an option

Save kokimame/46a3fd56296a9cc1acff6be8198faf78 to your computer and use it in GitHub Desktop.
Write PyQt5 docs into PDF
import requests
import pdfkit
from bs4 import BeautifulSoup
HOME_URL = "http://pyqt.sourceforge.net/Docs/PyQt5/"
SAVE_DIR = "./pyqt5-doc/"
r = requests.get(HOME_URL)
data = r.text
soup = BeautifulSoup(data, "html.parser")
hrefs = soup.find_all('a', attrs={"class":"reference internal"}, href=True)
url2pdf = {}
index = 0
for href in hrefs:
if '#' not in href['href']:
index += 1
id = (2-len(str(index)))*'0'+str(index) + "-"
pdfkit.from_url(HOME_URL + href['href'],
SAVE_DIR + id + href['href'].split('.')[0] + ".pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment