A simple Java-based web crawler that recursively explores web pages starting from a base URL, constructs an adjacency matrix representing the hyperlink structure, and analyzes which pages are most referenced by others.
- Recursively extracts links from web pages up to a maximum depth.
- Bypasses invalid SSL certificates (useful for development).
- Constructs an adjacency matrix to represent the web graph.
- Identifies the most referenced (contained) page using:
- Outgoing links (
Length) - Incoming links (
Width) - Redirection counts
- Outgoing links (
- Displays a mapping of links and their assigned indices.
- Java
- JSoup for HTML parsing
- Standard Java libraries
Crawler.java: Main class containing crawling logic, link indexing, and analysis.DirectedGraph.java: Class to represent the directed graph using an adjacency matrix.
- SSL Verification Disabled: Temporarily bypasses certificate validation for testing with
disableSSLVerification(). - Link Extraction:
extractWebpageLinks()recursively finds all links from the base URL. - Crawling:
crawl()goes through each link, adds it to the graph, and tracks link references. - Graph Construction: Uses
DirectedGraphto store the link relationships. - Analysis: Finds the most referenced page using:
- Outgoing edges (
searchByLength) - Incoming edges (
searchByWidth) - Link reference frequency
- Outgoing edges (
Index - Link Reference List:
[0]: https://example.com
[1]: https://example.com/about
[2]: https://example.com/contact
Detailed Crawl Information
Crawling: https://example.com
Link from: 0 -> 1 [https://example.com/about]
...
Adjacency Matrix:
0 1 0
0 0 1
...
Most Contained Link by Length: https://example.com/about
Most Contained Link by Width: https://example.com/contact
Most Contained Link by redirection Count: https://example.com/about with 3 occurrences.-
Prerequisites:
- Java 8 or higher
- JSoup library (add to your classpath)
-
Compile:
$ javac -cp .:jsoup-1.14.3.jar com/example/Crawler.java
-
Run:
$ java -cp .:jsoup-1.14.3.jar com.example.Crawler
- Max Depth is currently set to 3. You can change it via MAX_DEPTH constant.
- SSL verification is disabled by default for development purposes. Do not use in production.
- The crawler does not handle robots.txt compliance.