Click here to Skip to main content
6,594,088 members and growing! (17,742 online)
Email Password   helpLost your password?
General Programming » Internet / Network » General     Intermediate License: The Code Project Open License (CPOL)

WebResourceProvider goes .NET

By Ravi Bhavnani

A a simple yet powerful framework for retrieving useful information from public sources on the web.
C#, Windows, .NET 1.1, .NET 2.0VS.NET2003, VS2005, Dev
Posted:15 Jan 2006
Updated:17 Feb 2008
Views:34,177
Bookmarked:66 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
23 votes for this article.
Popularity: 5.21 Rating: 3.82 out of 5
3 votes, 13.0%
1
2 votes, 8.7%
2
1 vote, 4.3%
3
7 votes, 30.4%
4
10 votes, 43.5%
5

Introduction

This article (an improved .NET version of my C++ version) describes WebResourceProvider, a simple yet powerful framework for retrieving useful information from public sources on the web, such as:

Apart from being rewritten in C# from the ground up, this .NET version offers a smaller footprint than its C++ predecessor and makes it easy (almost trivial) to encapsulate functionality offered by online services into an object that can be manipulated by your application. Here are screenshots of some WebResourceProvider applications (listed at the end of this article) in action.

A domain walker that discovers the topology of the world wide web.
Domain Walker
An object that encapsulates Google's online natural language translation tools.
Google Translator
RSSChannel and RSSItem - a pair of objects that allow you to build an RSS reader.
Simple RSS Reader

A Word of Caution

Before you use WebResourceProvider to write the next killer app, be aware that there are legal and ethical issues regarding the use of information obtained from other sources. In particular, the terms of service (TOS) of content providers such as Yahoo, CNN, etc. clearly state what you can and cannot do with information retrieved from their sites. Even if you write a web resource provider for personal use only, you should take into consideration any undue stress that your object may put on a web server. The object's Pause property allows you to inject a delay between successive HTTP requests to help prevent overloading a server.

How it Works

WebResourceProvider works by initializing itself, constructing a URL to be retrieved, downloading the resource, and extracting useful information from the downloaded content. This process repeats until no more data needs to be downloaded.

You use WebResourceProvider by deriving from it, overriding getFetchUrl() and optionally overriding any of these virtual methods (shown in red in the flowchart on the right):

  • init()
  • getPostData()
  • parseContent()
  • continueFetching()

In the spirit of true object orientation, WebResourceProvider (unlike its C++ predecessor) doesn't provide a facility for parsing downloaded content. Readers are instead urged to use my StringParser class to help perform this task.

WebResourceProvider exposes the following properties:

Agent Gets and sets the user agent string.
Content Gets the retrieved content.
ErrorMsg Gets the last error message, if any.
FetchTime Gets the fetch timestamp.
Pause Gets and sets the minimum pause time interval (in mSec).
Referer Gets and sets the referer string.
Timeout Gets and sets the timeout (in mSec).

WebResourceProvider control flow

Demo applications

C# applications (with full source code) that use WebResourceProvider can be found here:

Revision History

  • 17 Feb 2008
    Updated links to sample applications.
  • 15 Jan 2006
    Initial version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ravi Bhavnani


Member
Ravi Bhavnani is an ardent fan of Microsoft technologies who loves building Windows apps, especially PIMs, system utilities, and things that go bump on the Internet. During his career, Ravi has developed expert systems, desktop imaging apps, enterprise marketing automation software, EDA tools, a platform to help people find, analyze and understand information, and trading software for institutional investors. He currently works for a company that provides advanced data visualization solutions for Microsoft technologies.

His interests include the .NET framework, reasoning systems, financial analysis and algorithmic trading, NLP, CHI and UI design. Ravi holds a BS in Physics and Math and an MS in Computer Science and is a Microsoft C# MVP. His claim to fame is that he crafted CodeProject's "joke" forum post icon.

Ravi's biggest fear is that one day he might actually get a life, although the chances of that happening seem extremely remote.
Occupation: Software Developer (Senior)
Company: Dundas Software
Location: Canada Canada

Other popular Internet / Network articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
GeneralUTF-7 Encoding Pinmembervarandas794:07 4 Nov '08  
GeneralRe: UTF-7 Encoding PinmemberRavi Bhavnani12:50 27 Nov '08  
GeneralNice job PinmemberGautam Sharma23:28 25 May '08  
GeneralRe: Nice job PinmemberRavi Bhavnani4:10 26 May '08  
GeneralWrong Encoding Pinmembertarasn11:58 4 Nov '07  
GeneralUpdated 14 Jun 2007 so what's new? PinmemberJan Stavngaard5:33 20 Jun '07  
AnswerRe: Updated 14 Jun 2007 so what's new? PinmemberRavi Bhavnani9:49 20 Jun '07  
GeneralGreat Work Pinmembermerlin98110:10 14 Jun '07  
GeneralRe: Great Work [modified] PinmemberRavi Bhavnani10:14 14 Jun '07  
GeneralRe: Great Work Pinmembermerlin98112:30 14 Jun '07  
GeneralRe: Great Work PinmemberRavi Bhavnani19:20 14 Jun '07  
GeneralWeb Page Authentication Pinmemberyachitha9:07 14 Jun '07  
GeneralWebsite that requires username/password Pinmemberme@vbman.com18:50 8 May '07  
GeneralRe: Website that requires username/password PinmemberRavi Bhavnani3:57 9 May '07  
QuestionStuck with abstract class PinmemberAndyTexas5:37 16 May '06  
AnswerRe: Stuck with abstract class PinmemberRavi Bhavnani5:44 16 May '06  
GeneralRe: Stuck with abstract class PinmemberAndyTexas6:42 16 May '06  
GeneralRe: Stuck with abstract class PinmemberRavi Bhavnani6:45 16 May '06  
GeneralGood Job PinmemberDavid7771:15 26 Apr '06  
GeneralRe: Good Job PinmemberRavi Bhavnani3:09 26 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Feb 2008
Editor: Sean Ewington
Copyright 2006 by Ravi Bhavnani
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project