Created
September 17, 2017 14:13
-
-
Save kokimame/46a3fd56296a9cc1acff6be8198faf78 to your computer and use it in GitHub Desktop.
Write PyQt5 docs into PDF
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
| 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