HtmlAgilityPACK showing Error " The given path's format is not supported" when loading html page from web server

c# html-agility-pack web-applications web-services

Question

I am using my local Apache Server and its address is 127.0.0.1 . and i trying to load html page from this server to C# programme using HTML Agility PACk but its showing

ERROR : The given path's format is not supported.

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

        docHtml.Load(@"htttp://127.0.0.1/2.htm"); // <---  error pointer showing here 

        foreach(HtmlNode link in docHtml.DocumentNode.SelectNodes("//a[@href]"))

        {  link.Attributes.Append("class","personal_info");


        }
        docHtml.Save("testHTML.html");


    }

Thank You very Much @Slaks after your suggesion i Changed my COde and its working Fine

 HtmlAgilityPack.HtmlDocument docHtml = new HtmlAgilityPack.HtmlDocument();
        HtmlAgilityPack.HtmlWeb docHFile = new HtmlWeb();

        docHtml = docHFile.Load("http://127.0.0.1/2.html");

Accepted Answer

doc.Load takes a path to a local file on disk.

You should use the HtmlWeb class:

HtmlDocument docHtml = new HtmlWeb().Load(url);



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why