WebClient.DownloadString(url) 当这个url返回404页面时,我怎样才能跳过这个?
我正在使用 WebClient.DownloadString(url) 下载网页,当 url 为 404 网页时,它会停止并且不再工作。 当我遇到这个错误时,我想跳过这些页面。
如果url是404页面,则不会开始下载。所以我无法解析未下载的数据......
I'm using WebClient.DownloadString(url) to download a web page, when a url a 404 web page it stops and doesn't work anymore.
I want to skip these pages when I got this fault.
if the url is 404 page, it doesn't start to download. so i can't parse the undownloaded data...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须捕获异常并测试 404:
You will have to catch the Exception and test for a 404:
您可以将代码放在
Try...Catch
块中并捕获 WebException.如果您想要更多地控制如何处理特定错误,可以使用 WebException 的Status
属性,该属性返回 WebExceptionStatus 枚举。You can put your code in a
Try...Catch
block and catch a WebException. If you want more control on how to handle specific errors, you can use the WebException'sStatus
property which returns a WebExceptionStatus enumeration.