Skip to content

Instantly share code, notes, and snippets.

@jackBonadies
Created April 13, 2019 21:02
Show Gist options
  • Save jackBonadies/0aaf4edd37a88bd53f4df006ec2e10d3 to your computer and use it in GitHub Desktop.
Save jackBonadies/0aaf4edd37a88bd53f4df006ec2e10d3 to your computer and use it in GitHub Desktop.
Beautiful Soup is a great library to parse and scrap text or images from sites based on html tags. In this case I simply got all image tags. Also, subprocess can spawn shell processes such as rm and mkdir to get rid of the previous set of images. We use wget to download images from source and ls with piping to get text file.
#!/usr/bin/env python3
from bs4 import BeautifulSoup
import requests
import os
import subprocess
source=requests.get('https://www.last.fm/user/lastpriest/library/albums').text
soup=BeautifulSoup(source,'lxml')
albums=soup.find_all('img')
imgUrls = []
for album in albums:
if '/64s' in album['src']:
imgUrls.append(album['src'].replace('/64s',''))
subprocess.call("rm -r top50images",shell=True)#create dir
subprocess.call("mkdir top50images",shell=True)#create dir
for url in imgUrls:
subprocess.call("wget "+ url +" -P ./top50images", shell=True) #download image
subprocess.call("ls top50images/ > listOfFiles.txt",shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment