Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html Agility Pack help

I'm trying to scrape some information from a website but can't find a solution that works for me. Every code I read on the Internet generates at least one error for me.

Even the example code at their homepage generates errors for me.

My code:

         HtmlDocument doc = new HtmlDocument();
         doc.Load("https://www.flashback.org/u479804");
         foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
         {
            HtmlAttribute att = link["href"];
            att.Value = FixLink(att);
         }
         doc.Save("file.htm");

Generates the following error:

'HtmlDocument' is an ambiguous reference between 'System.Windows.Forms.HtmlDocument' and 'HtmlAgilityPack.HtmlDocument' C:*\Form1.cs

Edit: My entire code is located here: http://beta.yapaste.com/55

All help is very appreciated!

like image 447
Victor Bjelkholm Avatar asked Oct 18 '10 20:10

Victor Bjelkholm


1 Answers

Use HtmlAgilityPack.HtmlDocument:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

The compiler is getting confused because two of the namespaces you have imported with using contain classes called HtmlDocument - the HTML Agility Pack namespace, and the Windows Forms namespace. You can get around this by specifying which class you want to use explicitly.

like image 99
Lucas Jones Avatar answered Oct 24 '22 03:10

Lucas Jones