Hey guys, I am having a problem figuring out how I would extract all the links from a webpage, and then filter them to get only a certain type of link.

For Example: i want to filter all the links that start with: http://www.googleads

How would I do this? (PS. Im using a webBrowser on my Windows Form)

Its pretty simple.

First you'll store all the "a" tags in an HtmlElementCollection and then check each one if it StartsWith "http://www.googleads". If so, then add it to the links list.

List<string> links = new List<string>();
HtmlElementCollection col = webBrowser1.Document.GetElementsByTagName("a");

foreach (HtmlElement elem in col)
{
   if (elem.GetAttribute("href").StartsWith("http://www.googleads"))
          links.Add(elem.GetAttribute("href"));
}

// Test it
foreach(string str in links)
  MessageBox.Show(str);

Thanks

no...thank you very much, i will try this right now and let u know if it worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.