first python program.. lyrics search

Gustavo Rahal listas at grahal.net
Fri Apr 2 22:07:11 EST 2004


Hi

I'm trying to learn python by doing something that I think it would be 
nice; Search lyrics using some websites like www.musicsonglyrics.com, 
http://www.sing365.com
I am trying to parse the html code and get the information that i need. 
Since I am not very good with programing I am stuck on this part.
Let's take the www.musicsonglyrics.com website as an example. So let's 
say Metallica lyrics would be on www.musicsonglyrics.com/M.htm. Getting 
the first letter, requesting the M.htm page and checking if Metallica is 
in the html code is easy. Here is what I did up to now:

artist = raw_input("Name of the artist: ")
music = raw_input("Name of the music: ")
                                                                                                                        

url = "http://www.musicsonglyrics.com/" + artist[0].capitalize() + ".htm"
f = 
urllib2.urlopen(url)                                                                                                                    

found = 0
lines = f.readlines()
f.close()
for x in lines:
        if x.find(artist) != -1:
                found = 1
                                                                                                              
                                                                                                                       

if found:
        print "OK"
else:
        print "No"


The problem is once I have the M.htm page I don't now how to get from 
the html code the "http://www.musicsonglyrics.com/M/Metallica/Metallica 
lyrics.htm" link to proceed with the search. I tried to read about 
Regular Expressions but I think I'm to dumb for it.

Any ideas? Maybe my approach is completely wrong....

Appreciate any help
Gustavo





More information about the Python-list mailing list