raspberrypi – Kyle R. Conway

Download Issue of MagPi with python from Raspberry Pi 3 Model B+

# MagPi Issue Downloader

## Import 
import urllib.request
import shutil
import requests
import os
from bs4 import BeautifulSoup

# Identify URL to parse
url = 'https://www.raspberrypi.org/magpi-issues/'

# soup it
Link = requests.get(url)
soup = BeautifulSoup(Link.content,"html5lib")

# get all link tags
tags = soup('a')

# loop tags
for hlink in tags:
	# create variable for full url
	issue = hlink.get('href', None)
	# only follow hlinks with PDF in the url
	if 'pdf' in issue:
		# download files with wget to current directory
		print("Downloading: " + issue)
		issue_link = url + issue
		os.system('wget %s'%issue_link)