Error downloading Html using HtmlAgilityPack Library in C#

c# html-agility-pack

Question

Attempting to scrape this Website but failing.

An exception is thrown when the message hasError downloading Html

enter image description here

C# Code

    async public static Task<HtmlDocument> GetDocument()
    {
        HtmlDocument doc = null;
        string url = "https://www.finedininglovers.com/recipes/appetizer/vegan-dishes-white-asparagus/";
        try
        {
            HtmlWeb web = new HtmlWeb();
            doc = await web.LoadFromWebAsync(url);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
        }
        return doc;
    }

attempted settingMozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 as the UserAgent, yet it is still inoperative

1
1
4/12/2018 4:38:40 AM

Accepted Answer

Here, a problem is formed Link

The code below operates as described in the github link.

HtmlAgilityPack.HtmlDocument doc = null;
string url = "your_link";

HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
doc = web.Load(url);
var html = doc.DocumentNode.OuterHtml;
1
4/13/2018 3:02:56 PM


Related Questions





Related

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