5/28
Part 2 of 6 · Breadth firstLearn and do

Search the site breadth first

Set the threads aside for a moment. First, which pages does a crawl visit, and in what order?

A site is a graph, and a crawl walks it

The tests' small site, crawled breadth firstInteractive
//a/b#topother.com/x/cnews.example.com/n/broken/never
in the frontier fetched fetch failed another host
frontier, popleft takes the left end:/seen: 1
The start URL goes into the frontier and into seen, before anything is fetched.

A site is a graph: pages are the points, and links are the arrows between them. A crawl starts at one page and follows the arrows. Nothing ever finds /never, because the fetch of /broken fails. Here is the small site as code:

E = "http://example.com"
SITE: dict[str, list[str]] = {
    f"{E}/": [f"{E}/a", f"{E}/b#top", "http://other.com/x"],
    f"{E}/a": [f"{E}/", f"{E}/c", "http://news.example.com/n"],
    f"{E}/b": [f"{E}/a#part", f"{E}/broken"],
    f"{E}/c": [],
    f"{E}/broken": [f"{E}/never"],
}
calls: list[str] = []


def fetch(url: str) -> list[str]:
    """The page's links, as written. /broken raises, like a refused connection."""
    calls.append(url)
    if url == f"{E}/broken":
        raise ConnectionError("refused")
    return SITE.get(url, [])


print(fetch(f"{E}/b"))
Predict

What does fetch(f"{E}/b") return?

Pick one to see what it prints.
Pick an answer above to see the rest