A high-performance, concurrent web crawler built in Java. This project demonstrates core Object-Oriented Programming principles, Java concurrency, and HTML parsing using the Jsoup library.
- Multithreading: Utilizes Java's
Runnableinterface andThreadinstances to crawl multiple web pages simultaneously, significantly speeding up the data extraction process. - Thread-Safe Memory Management: Implements a
ConcurrentHashMapbackedSetto track visited URLs, preventing race conditions and duplicate processing across multiple bot threads. - Recursive Depth Control: Features a configurable
MAX_DEPTHlimit to prevent infinite crawling loops and stack overflow errors. - DOM Parsing: Leverages Jsoup to connect to URLs, handle HTTP responses, and extract specific HTML elements (like
<a>tags and document titles).
- Java Development Kit (JDK) 8 or higher
- Jsoup Library (Added to your IDE classpath, or via Maven/Gradle)
mtWebCrawler(Package)WebCrawler.java: The core engine implementing theRunnableinterface. It handles network requests, tracks shared visited links safely across threads, and recursively parses DOM trees for nested links.Main.java(or equivalent entry point): Initializes the target seed URLs and spawns theWebCrawlerthreads.
- Clone the repository.
- Ensure the Jsoup
.jarfile is added to your project's build path (or add the dependency to yourpom.xmlif using Maven). - Compile the
mtWebCrawlerpackage. - Run your main class to start the bot threads.
// Example usage:
WebCrawler bot1 = new WebCrawler("[https://example.com](https://example.com)", 1);
WebCrawler bot2 = new WebCrawler("[https://news.ycombinator.com](https://news.ycombinator.com)", 2);