Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple python3 script for downloading all free issues of Linux Journal
#
#
# Simple python3 script for downloading all free issues of Linux Journal
# The script will download all the available versions: pdf, epub and mobi
#
# Powered By Andrea Draghetti
#
#
#!/usr/bin/python3
import os
import requests
from bs4 import BeautifulSoup
headerdesktop = {"User-Agent": "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
"Accept-Language": "en-EN"}
timeoutconnection = 120
url = "https://secure2.linuxjournal.com/pdf/dljdownload.php"
page = requests.get(url, headers=headerdesktop, timeout=timeoutconnection)
soup = BeautifulSoup(page.text, "html.parser")
for link in soup.find_all("a"):
destinantion_directory = "./ljdownload"
if not os.path.exists(destinantion_directory):
os.makedirs(destinantion_directory)
if link.get("href"):
if "download" in link.get("href"):
downloadurl = link.get("href") + "&action=spit"
filename = downloadurl.split("-")[2]
fileextension = downloadurl.split("=")[2].split("-")[0]
print("Download: %s.%s" % (filename, fileextension))
r = requests.get(downloadurl, headers=headerdesktop, timeout=timeoutconnection, stream=True)
if r.status_code is 200:
with open(destinantion_directory + "/" + filename + "." + fileextension, "wb") as f:
f.write(r.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.