panindra
panindra

Reputation: 646

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");

Upvotes: 6

Views: 4035

Answers (1)

SLaks
SLaks

Reputation: 887365

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

You should use the HtmlWeb class:

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

Upvotes: 18

Related Questions