You need to register the PostRequestHandler event in an PostRequestHandler instance, it will be raised after each loaded document, and you will get access to the HttpWebResponse object. It has a property for StatusCode .
HtmlWeb web = new HtmlWeb(); HttpStatusCode statusCode = HttpStatusCode.OK; web.PostRequestHandler += (request, response) => { if (response != null) { statusCode = response.StatusCode; } } var doc = web.Load(completeUrl) if (statusCode == HttpStatusCode.OK) {
Looking at the HtmlAgilityPack code on GutHub, itβs even simpler, HtmlWeb has the StatusCode property, which is set with the value:
var web = new HtmlWeb(); var document = web.Load(completeurl); if (web.StatusCode == HttpStatusCode.OK) { var urls = document.DocumentNode.Descendants("img") .Select(e => e.GetAttributeValue("src", null)) .Where(s => !String.IsNullOrEmpty(s)).ToList(); }
source share