1236. Web Crawler

You are given a start URL startUrl, a list of all page URLs urls, and a directed edge list edges. Each edge [i, j] means that the page at urls[i] links to the page at urls[j], which is exactly what an HtmlParser.getUrls call on urls[i] would return.

Implement a web crawler that starts at startUrl, repeatedly discovers links from the pages it visits, and returns every URL that is reachable from startUrl under the same hostname as startUrl. You may return the answer in any order.

The crawler must:

  • Start from the page startUrl.
  • Follow outgoing edges exactly as HtmlParser.getUrls would return them.
  • Never crawl the same link twice.
  • Explore only links whose hostname equals the hostname of startUrl.

The hostname is the text after http:// and before the first /. Trailing slashes are significant: http://news.yahoo.com and http://news.yahoo.com/ are different URLs and are crawled independently.

Examples
Input: ["http://h0.example.com/p0",["http://h0.example.com","http://h0.example.com/p0","http://other0.com/x","http://h0.example.com/a0","http://z0.com/q"]]
Output: ["http://h0.example.com","http://h0.example.com/a0","http://h0.example.com/p0"]
Hints
Related Problems

1236. Web Crawler

You are given a start URL `startUrl`, a list of all page URLs `urls`, and a directed edge list `edges`. Each edge `[i, j]` means that the page at `urls[i]` links to the page at `urls[j]`, which is exactly what an `HtmlParser.getUrls` call on `urls[i]` would return.