NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

Glossary

Breadth-first crawling and depth-first crawling

Breadth-first crawling visits every page one link away from the start before moving two links away, which keeps a crawl close to the most important pages first.

The two orders

A site is a graph: pages are nodes, links are edges. Crawl order decides which discovered page you visit next. Breadth-first search (BFS) uses a first in, first out queue, so pages come out in the order they were found and the crawl spreads level by level. Depth-first search (DFS) uses a last in, first out stack, so the crawler follows the newest link immediately and goes deep before it comes back up.

Why BFS is the usual default

Pages close to the home page tend to matter more: category pages, main listings, important articles. BFS reaches all of them early, so if the crawl is cut short you still have the core of the site. It also spreads requests across many sections, which looks less like a bot hammering one corner. Most frameworks default to it or something close to it.

import collections

def crawl(start, max_depth, fetch_links):
    seen, todo = {start}, collections.deque([(start, 0)])
    while todo:
        page, depth = todo.popleft()        # FIFO gives breadth-first
        if depth == max_depth:
            continue
        for link in fetch_links(page):
            if link not in seen:
                seen.add(link)
                todo.append((link, depth + 1))
    return seen

Swap popleft() for pop() and the same function becomes depth-first.

When depth-first fits better

DFS suits tasks where one path holds everything you need, for example walking a single category through all its pages before moving on, or following a thread of replies to the end. It keeps memory low because the frontier is only as big as the current path. The danger is spider traps: calendars, endless filters or session IDs that create infinite depth. Always set a depth limit when you go deep.

Best-first and priority crawling

Real crawlers often use neither pure order. They give each URL a score (fresher, closer to the root, matching a pattern such as /product/) and pull the highest score first from a priority queue. This is how you focus a crawl on product detail pages while still discovering new categories. A request queue with priorities supports both BFS and best-first with one data structure.

Crawl order and bot checks

Order affects how a site sees you. A depth-first run that pages through one listing at speed is easy to spot, and sites commonly raise a challenge after a burst of deep, sequential requests. A breadth-first run touches many paths with natural looking gaps. Neither order makes you invisible, so plan for the moment a page answers with a challenge: hold that URL, solve the challenge, and retry. For a Cloudflare Turnstile widget the token usually arrives under 3 seconds, and you pay only when a task is solved.

Scope rules regardless of order

  • Stay on the domains you mean to crawl.
  • Respect robots.txt and skip disallowed paths.
  • Normalize URLs so the same page is not queued twice.
  • Set both a depth limit and a total page budget.

Common questions

What data structure gives breadth-first crawling?

A first in, first out queue. Using a last in, first out stack instead turns the same loop into a depth-first crawl.

Is BFS or DFS better for discovering a whole site?

BFS, because it reaches the shallow, well linked pages early and still gives useful results if the crawl stops halfway.

What is a spider trap?

A part of a site that produces endless unique URLs, such as calendars or filter combinations, which can trap a deep crawl.

Does crawl order change how often I see CAPTCHAs?

It can. Fast, sequential deep paging looks more automated than spreading requests across many sections.

What is best-first crawling?

Each discovered URL gets a score and the crawler always fetches the highest scoring one next, using a priority queue.

Keep reading