[英]How to check if it is 404 error page(page does not exist) using HtmlAgilityPack
[英]How to identify websites that give page not found error using HTMLAgilityPack
以下网站加载但说“找不到页面”。 是否有标识这种情况的测试(“if”语句)?
例如: - 像这样的网站......
http://www.vccircle.com/500/news/news-roundup-amrapali-raising-rs-80cr-from-icici-prudential
代码如下...我不希望执行停止此错误,它应该只报告它并继续执行。
try
{
string s = w.DownloadString(TargetUrl);
hd.LoadHtml(s);
}
catch (Exception e)
{
throw e;
}
我发现一旦尝试得到错误,执行将捕获并阻止整个应用程序。 我明白这必须是一个与特殊处理有关的基本问题,但我正在学习......所以请帮忙。
使用WebClient.DownloadString
获取网页。
如果它没有找到,你会得到一个WebException
,和它的((HttpWebResponse)ex.Response).StatusCode
将HttpStatusCode.NotFound
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.