0

I have some strings with the content like this

<a href="http://example.com/2014/06/22/new-idea-about-life.zip">One</a>
<a href="http://example.com/2014/06/22/new-idea-about-life-rar.rar">Two</a>

I need this output:

http://example.com/2014/06/22/new-idea-about-life.zip
http://example.com/2014/06/22/new-idea-about-life-rar.rar
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
j kobe
  • 1
  • 1
    Take a look at html agility pack. It is a library that makes working with html strings or files easier. Supports linq-to-objects amongst other things. Also allows you to extract attributes from tags, which is what you need to do here. – Umair Jan 28 '17 at 14:57
  • thanks. does it have help? i dont know how to use it – j kobe Jan 28 '17 at 15:25

1 Answers1

0

HTML Agility Pack is a good library to parse HTML in C#.

An example for extracting urls is:

var html = "<a href=\"http://reallife.com/2014/06/22/new-idea-about-life.zip\">New idea about life (zip) (25MB)</a><a href=\"http://reallife.com/2014/06/22/new-idea-about-life-rar.rar\">New idea about life (rar) (23MB)</a>
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
var links = new List<string>();
foreach (var link in htmlDoc.DocumentNode.SelectNodes("//a[@href]"))
{
    links.Add(link.GetAttributeValue("href", string.Empty));    
}
// do something with the links inside the links-List
Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67