first python program.. lyrics search

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gustavo Rahal

    first python program.. lyrics search

    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,

    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.musicsongly rics.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.musicsongly rics.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


  • Mel Wilson

    #2
    Re: first python program.. lyrics search

    In article <mailman.295.10 80961642.20120. python-list@python.org >,
    Gustavo Rahal <listas@grahal. net> wrote:[color=blue]
    >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 [ ... ]
    >The problem is once I have the M.htm page I don't now how to get from
    >the html code the "http://www.musicsongly rics.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....[/color]

    Look up htmllib in Python libraries. It's not a small
    job, but you'll have learned a lot by the time you've
    finished.

    Good Luck. Mel.

    Comment

    Working...