RE: System.Net.Webclient screen scraping: how to gracefully handle 403 (and other) errors?
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Wed, 10 Jan 2007 08:29:31 GMT
Hello KF,
Based on your description, you're using the webclient class to request many
web pages programmatically in ASP.NET page code. However, since some page
may raise some exception, your client loop code in ASP.NET page break,
correct?
As for the 403 error, it is normally caused by the security authorization
checking at server-side fails. I'm not sure whether there is any other
particular scenario here, however, if what you want is simply captuer and
ignore such error and continue the loop, you can just add a try catch block
around your webclient class's downloadXXX method call and if any exception
captured you can simply ignore it and skip the current loop. e.g.
=======================
foreach (DataRow dr in s.Tables[0].Rows)
{
counter++;
System.Net.WebClient wc = new WebClient();
try
{
string strData =
wc.DownloadString("http://whatever.org/article.asp?articleid=" +
dr[0].ToString());
}catch(Exception ex)
{
//ignore and continue the loop
}
....................................
}
=========================
Does this work for your scenario?
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- References:
- Prev by Date: Re: System.Net.Webclient screen scraping: how to gracefully handle 403 (and other) errors?
- Next by Date: Re: Submit a form by pressing the enter key
- Previous by thread: Re: System.Net.Webclient screen scraping: how to gracefully handle 403 (and other) errors?
- Next by thread: Thanks Re: System.Net.Webclient screen scraping: how to gracefully handle 403 (and other) errors?
- Index(es):
Relevant Pages
|