Sharath
Sharath

Reputation: 2428

Error downloading Html using HtmlAgilityPack Library in C#

Trying to scrape this Website but unable to do it..

It throws an exception with the message has Error 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;
    }

Tried setting Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 as the UserAgent but still not working

Upvotes: 1

Views: 488

Answers (1)

Sharath
Sharath

Reputation: 2428

An issue is created here Link

Below code works as mentioned 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;

Upvotes: 1

Related Questions