The Concurrent Web Crawler is a Go-based application designed to crawl web pages efficiently using Go's powerful concurrency features. This project was undertaken to deepen my understanding of Go's concurrency model, specifically Goroutines, Channels, and synchronization primitives.
- Learn Go's Concurrency Model: Gain hands-on experience with Goroutines and Channels.
- Implement Synchronization: Understand and apply synchronization tools like Mutexes and WaitGroups.
- Build a Scalable Application: Create a web crawler that can efficiently handle multiple tasks concurrently.
- Respect Web Crawling Ethics: Implement features to respect robots.txt and avoid overloading servers.
- Concurrent Crawling: Utilizes Goroutines to fetch and parse web pages concurrently.
- URL Parsing and Normalization: Extracts and normalizes links from HTML content.
- Visited URLs Tracking: Keeps track of visited URLs to prevent duplicate processing.
- Robots.txt Compliance: Checks and respects robots.txt directives for each domain.
- Rate Limiting: Implements rate limiting to prevent overwhelming web servers.
- Graceful Shutdown: Handles system signals to ensure the crawler can be stopped gracefully.
concurrent-web-crawler/
├── fetch.go
├── go.mod
├── go.sum
├── main.go
├── parse.go
├── README.md
└── robots.go
git clone https://github.com/0ritam/Concurrent-Web-Crawler.git
cd concurrent-web-crawlergo mod downloadgo run .- Goroutines: Learned how to launch lightweight threads using Goroutines, allowing functions to run concurrently.
- Channels: Understood how to use Channels for communication between Goroutines, enabling safe data transfer without explicit locking.
- WaitGroups: Used
sync.WaitGroupto wait for a collection of Goroutines to finish executing. - Mutexes: Applied
sync.Mutexto protect shared resources and prevent race conditions.
- HTTP Requests: Gained experience with the
net/httppackage to perform HTTP requests and handle responses. - HTML Parsing: Utilized the
goquerylibrary to parse HTML documents and extract links efficiently. - URL Normalization: Learned to normalize and resolve relative URLs to absolute URLs, ensuring accurate crawling paths.
- Robots.txt Compliance: Implemented functionality to read and respect
robots.txtfiles, adhering to website crawling policies. - Rate Limiting: Introduced rate limiting to control the frequency of HTTP requests, preventing server overloads.
- Domain Restrictions: Limited crawling to specific domains to avoid unintended crawling of external sites.
- Robust Error Handling: Developed strategies for retrying failed requests and handling various types of errors gracefully.
- Logging: Employed the
logpackage to record significant events and errors, aiding in debugging and monitoring.
This project provided a comprehensive exploration of Go's concurrency features and practical application in building a real-world tool. By developing the Concurrent Web Crawler, I not only enhanced my technical skills but also gained valuable insights into software design, ethical considerations, and best practices in Go programming.