Skip to content

Instantly share code, notes, and snippets.

@ohbob
Last active May 16, 2022 17:54
Show Gist options
  • Select an option

  • Save ohbob/e410f706f60db0ac94e3323e4e4d2e63 to your computer and use it in GitHub Desktop.

Select an option

Save ohbob/e410f706f60db0ac94e3323e4e4d2e63 to your computer and use it in GitHub Desktop.
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