开发者

How to identify websites that give page not found error using HTMLAgilityPack

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 questi开发者_运维知识库on related to exceptional handling, but i am learning...so please help.


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 be HttpStatusCode.NotFound

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜