Skip to content

Instantly share code, notes, and snippets.

@drego85
Created August 27, 2019 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drego85/b667315348d3959ef3b7d7904215741c to your computer and use it in GitHub Desktop.
Save drego85/b667315348d3959ef3b7d7904215741c to your computer and use it in GitHub Desktop.
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