5,663,486 members and growing! (18,604 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

A Web Spider Library in C#

By Uwe Keim

An article about a spider library to grab websites and store them locally.
Windows, .NET, Visual Studio, WebForms, ASP.NET, Dev

Posted: 10 Sep 2006
Updated: 18 Sep 2007
Views: 47,468
Bookmarked: 80 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
20 votes for this Article.
Popularity: 4.52 Rating: 3.47 out of 5
4 votes, 20.0%
1
2 votes, 10.0%
2
2 votes, 10.0%
3
4 votes, 20.0%
4
8 votes, 40.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Sample Image - ZetaWebSpider.png
Don't fear, it's just a web spider ;-)

Introduction

Today, while looking through some older code, I came across a set of classes I wrote at the beginning of this year for a customer project.

The classes implement a basic web spider (also called "web robot" or "web crawler") to grab web pages (including resources like images and CSS), download them locally and adjust any resource hyperlinks to point to the locally downloaded resources.

While this article is not a full-featured article with detailled explanations as I usually like to write, I still want to put the code online with this short article. Maybe that some reader still takes some ideas from this code and use it as a starting point for his own project.

Overview

The classes allow for synchronous as well as asynchronous download of the web pages, allowing multiple options to be specified like hyperlink-depth to follow and proxy settings.

The downloaded resources get their own new file names, based on the hash code of the original URL. I did this for simplifications (for me as the programmer).

To parse a document I am using the SGMLReader DLL from the GotDotNet website.

Also, since I didn't need it for the project I wrote, the library does not care about "robots.txt" or throttling or other features.

Using the code

The download for this article contains the library ("WebSpider") and a testing console application ("WebSpiderTest"). The testing application is rather short and should be rather easy to understand.

Basically you do create an instance of the WebSiteDownloaderOptions class, configure several parameters, create an instance of the WebSiteDownloader class, optionally connect event handlers and then tell the instance to either start synchronously or asynchronously processing the given URL.

History

  • 2007-09-17: Fixed several issues.
  • 2006-09-10: Initially release of the article.

License

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

About the Author

Uwe Keim


Sitebuilder
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He is also teaching programming to students at the local "Fachhochschule".

In his free time, he does climbing, running and mountainbiking. You can watch him most of the day (and probably night) programming.

Some cool, free software from us:

Zeta Producer Desktop CMS
Intuitive, completely easy-to-use CMS for Windows.

Zeta Helpdesk
Open Source ticket- and helpdesk software for Windows and web.

Zeta Uploader
Easily send large files by e-mail. Windows and web client available.

Desargues
Innovative, lean and neat calculator for Windows. You never want to use Calc.exe again!
Occupation: Software Developer
Company: zeta software GmbH
Location: Germany Germany

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh)FirstPrevNext
QuestionI am getting an unhandled exception while running the test projectmemberMember 471182410:47 3 Jun '08  
GeneralException Running Testmembercornix410:49 30 Apr '08  
Generalso goodmemberokzhuce21:18 28 Apr '08  
GeneralRe: so goodsitebuilderUwe Keim21:43 28 Apr '08  
GeneralhellomemberMember 451146415:48 18 Feb '08  
QuestionVery nicememberaaron_myers5:59 18 Sep '07  
AnswerRe: Very nicesitebuilderUwe Keim21:37 18 Sep '07  
GeneralRe: Very nicememberaaron_myers4:53 22 Oct '07  
QuestionRe: Very nicememberbabaa17:57 24 Feb '08  
GeneralGreat Appmemberrdissell6:14 1 Aug '07  
GeneralGreat job. But i met a problemmemberBlueLoveCyn22:28 14 Sep '06  
GeneralYour Project No Workymembereasy_coder4:04 12 Sep '06  
GeneralRe: Your Project No WorkysitebuilderUwe Keim4:19 12 Sep '06  

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

PermaLink | Privacy | Terms of Use
Last Updated: 18 Sep 2007
Editor:
Copyright 2006 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project