如何使用 HTMLAgilityPack 识别出现页面未找到错误的网站
以下网站加载但显示“找不到页面”。是否有一个测试(“if”语句)来识别这种情况?
例如:- 像这样的网站...
http://www.vccircle.com/500/news/news-roundup-amrapali-raise-rs-80cr-from-icici-prudential
代码如下...我不想要执行到此错误时停止,它应该只是报告它并继续执行。
try
{
string s = w.DownloadString(TargetUrl);
hd.LoadHtml(s);
}
catch (Exception e)
{
throw e;
}
我发现一旦尝试获取错误,执行就会捕获并阻塞整个应用程序。我知道这一定是与异常处理相关的基本问题,但我正在学习......所以请帮助。
The following website loads but says "page not found". Is there a test ("if" statement) that identifies this condition?
Ex:- Websites like this ...
http://www.vccircle.com/500/news/news-roundup-amrapali-raising-rs-80cr-from-icici-prudential
The code is as follows...i don't want the execution to stop on this error, it should just report it and continue with the execution.
try
{
string s = w.DownloadString(TargetUrl);
hd.LoadHtml(s);
}
catch (Exception e)
{
throw e;
}
I find that once try get the error the execution is going to catch and is blocking the whole application. i understand this must be a basic question related to exceptional handling, but i am learning...so please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
WebClient.DownloadString
获取网页。如果未找到,您将收到
WebException
,其((HttpWebResponse)ex.Response).StatusCode
将为HttpStatusCode.NotFound
Use
WebClient.DownloadString
to fetch the web page.If it's not found, you'll get a
WebException
, and its((HttpWebResponse)ex.Response).StatusCode
will beHttpStatusCode.NotFound