Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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");
like image 745
panindra Avatar asked Jul 01 '11 02:07

panindra


1 Answers

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

You should use the HtmlWeb class:

HtmlDocument docHtml = new HtmlWeb().Load(url);
like image 155
SLaks Avatar answered Oct 16 '22 08:10

SLaks