import urllib,re,sys; from BeautifulSoup import BeautifulSoup inp = str(sys.argv[1]) a = urllib.urlopen("http://www.azlyrics.com/lyrics/" + inp + ".html").read() soup = BeautifulSoup(a) b = soup.findAll(style="margin-left:10px;margin-right:10px;") artist = re.search(r'ArtistName = "(.*?)"', a).group(1) title = re.search(r'SongName = "(.*?)"', a).group(1) if not b: print "Song not found :/" sys.exit c = str(b).replace("[]", "") try: file = open(artist + " - " + title + ".html", "w") except IndexError: print "Song name not in correct format: artistname/songname" print "Example: amateurtransplants/londonunderground" sys.exit file.write(c) file.close() print "Success. Lyrics written to " + file.name