0

how can I download all the linked mp3s from a web page?

example html

<a href=​"http:​/​/test.com/linkofmusic1.mp3" download=​"Song.mp3">​
<a href=​"http:​/​/test.com/linkosong2.mp3" download=​"music2.mp3">​
Eonasdan
  • 7,563
  • 8
  • 55
  • 82
Alessio Koci
  • 1,103
  • 11
  • 24

1 Answers1

1

You can use HtmlAgilityPack to get all the link with href having .mp3 extension

Example:

 HtmlDocument doc = new HtmlDocument();
 doc.Load("file.htm");

 List<string> mp3Links = new List<string();
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
 {
    if(link != null)
    {
      if(link["href"].EndsWith(".mp3"))
      {
        mp3Links.Add(link["href"].Value);
      }
    }
 }
HatSoft
  • 11,077
  • 3
  • 28
  • 43