Reputation: 239
I do have an problem in C# that is
Suppose there is one website's link....www.xyz.com
and 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
Upvotes: 0
Views: 1583
Reputation: 1038710
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);
}
}
}
Upvotes: 1