how to remove htmldocument.cs not found error in html agility pack

c# html-agility-pack


class Response:

public string WebResponse(string url) //class through which i'll have link of website and will parse some divs in method of this class
    string html = string.Empty;
        HtmlDocument doc = new HtmlDocument(); //when code comes here it gives an error htmldocument.cs not found,and open window for browsing source
        WebClient client = new WebClient(); // even if i put htmlWeb there it still look for HtmlWeb.cs not found
        html = client.DownloadString(url); //is this from some breakpoint error coz i set only one in method where i am parsing,
    catch (Exception)
        html = string.Empty;

    return html; //please help me to remove this error using html agility pack with console application 

even if i make new project and run code it stuck here and i have added DLL too still it is giving me this error please help me to remove this error

3/7/2016 7:39:47 AM

Accepted Answer

that error is sometimes because of version of you are using of Nuget html agility pack,update your nuget in the visual studio gallery then try installing html agility pack and run in your project

4/17/2016 5:52:32 AM

Popular Answer

WebResponse is an abstract class meaning it is a reserved word first of all. Second - In order to use WebResponse a class has to inherit from WebResponse ie.

public class WR : WebResponse

Also. Your current code has nothing to with Html Agility Pack. If you want to load the html of a webpage into a HtmlDocument - do the following:

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

    var temp = new Uri(url);
    var request = (HttpWebRequest)WebRequest.Create(temp);
    request.Method = "GET";
    using (var response = (HttpWebResponse)request.GetResponse())
        using (var stream = response.GetResponseStream())
            htmlDoc.Load(stream, Encoding.GetEncoding("iso-8859-9"));
}catch(WebException ex){

Then in order to get nodes in the Html Document you have to use xPath like so:

HtmlNode node = htmlDoc.DocumentNode.SelectSingleNode("//body");

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow