Last active
May 16, 2022 17:54
-
-
Save ohbob/e410f706f60db0ac94e3323e4e4d2e63 to your computer and use it in GitHub Desktop.
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 | |
| from bs4 import BeautifulSoup | |
| def download_file(download_url, filename): | |
| r = requests.get(download_url) | |
| with open(f"MagPi-{filename}.pdf", "wb") as code: | |
| print(f"Downloading => {filename} issue") | |
| code.write(r.content) | |
| def parsemagazine(n): | |
| print(f"Parsing => {n} issue") | |
| URL = f"https://magpi.raspberrypi.com/issues/{n}/pdf/download" | |
| page = requests.get(URL) | |
| soup = BeautifulSoup(page.content, "html.parser") | |
| links = soup.find_all("a", class_="c-link", href=True) | |
| if len(links) > 0: | |
| download_file(f"https://magpi.raspberrypi.com{links[0]['href']}", n) | |
| issues = 117 | |
| [parsemagazine(e) for e in range(1, issues + 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment