

[mp3 | TagOpen "a" atts , ("href",mp3) , takeExtension mp3 == ".mp3"]





import System.FilePath

import System.Environment

import Text.HTML.TagSoup



main = do

[src] txt mapM_ putStrLn [mp3 | TagOpen "a" atts , ("href",mp3) , takeExtension mp3 == ".mp3"]



I just read a blog article entitled Kid's play with HTML in Haskell , where the author extracts some information from an HTML document, using the Haskell XML Toolbox . I have an alternative XML/HTML library, TagSoup , so I decided to implement their problem with my library.Given an HTML file, extract all hyperlinks to mp3 files.The code is a list comprehension. The first line says use TagSoup to parse the text, and pick all "a" links. The second line says pick all "href" attributes from the tag you matched. The final line uses the FilePath library to check the extension is mp3.The above fragment is all the TagSoup logic, but to match exact the interface to the original code, we can wrap it up as so:If you have a desire to quickly get a bit of information out of some XML/HTML page, TagSoup may be the answer. It isn't intended to be a complete HTML framework, but it does nicely optimise fairly common patterns of use.