0

I do have an problem in C# that is
Suppose there is one website's link....www.xyz.comand suppose there are 25 links on the website's home page.

Now i want that using C# and asp.net i do have an String array suppose LinkArray[n] and TabArray[n] {string array} and i want that there should be a program which can list all the links in the array as follows.

suppose links are : <a href="xyz.com/home.html">Home</a> <a href="xyz.com/Contact.html"> </a> etc

Now i want that in two arrays it should be stored as

TabArray[2]= {Home,Contact}
LinkArray[2]={xyz.com/home.html,xyz.com/contact.html}

Likewise i want that i can get listed all the links details in of any web page. Please suggest me some code/ guide tutorials Thanks

Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
ItsLockedOut
  • 229
  • 1
  • 4
  • 17
  • possible duplicate of [Looking for C# HTML parser](http://stackoverflow.com/questions/100358/looking-for-c-html-parser) – Bala R Oct 08 '11 at 16:14

1 Answers1

1

You could use sharp-query or Html Agility Pack to parse HTML. Here's an example with sharp-query:

using System;
using XCSS3SE;

class Program
{
    static void Main()
    {
        var sq = new SharpQuery("http://stackoverflow.com");
        foreach (var el in sq.Find("a[href]"))
        {
            Console.WriteLine("{0} : {1}", el.InnerText, el.Attributes["href"].Value);
        }
    }
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • There are hundreds of similar questions with hundreds of similar answer. This post should be closed as dupe. – Bala R Oct 08 '11 at 16:13
  • I knew it but none of them contains efficient answers and most of them are old [outdapted] so i had to ask it again. – ItsLockedOut Oct 08 '11 at 16:15