# What is a web spider or search engine spider? | Spider Guides

A web spider is a program that reads web pages by following the links between them. How a search engine spider works, with 40 lines of Python you can run.

Canonical: https://spider.cloud/guides/what-is-a-web-spider/

## What is a web spider?

A web spider is a program that reads web pages by following the links between them. It starts with a list of addresses. It fetches the first page, collects the links on that page, and adds the ones it has not seen to the list. Then it does the same for the next address, and the next, until the list is empty or someone stops it.

The name comes from the web. A program that moves from thread to thread across the World Wide Web got called a spider, and what it does got called crawling. Web crawler, robot and bot are other names for the same program.

Some people type “spider web” when they mean this program. In computing that phrase is not a technical term. The web is the set of linked pages, and the spider is the program that walks it.

## What is a search engine spider?

A search engine spider is a web spider that a search engine runs to find pages for its index. Googlebot is Google’s and Bingbot is Bing’s.

A search engine does three jobs in order. It crawls, which means its spider fetches pages. It indexes, which means it stores what each page says. It ranks, which means it picks the pages to show for a query. The spider does the first job, and the other two depend on it. A page the spider has not fetched is not in the index, so it cannot appear in a result.

A search engine spider finds a new page in one of two ways. Either a page it already knows links to the new one, or the site lists the address in a sitemap file. It also returns to pages it has already read, because pages change.

## How does a web spider work?

A spider is a loop around a queue. The queue holds the addresses still to visit and is often called the frontier. Each turn of the loop does four things:

1. Take the next address from the frontier.
2. Check the site’s robots.txt and skip the address if the file disallows it.
3. Fetch the page and read every link on it.
4. Add each link that is on the same site and has not been seen before.

Written as a program, that loop is 40 lines of Python and needs no packages.

```python
import sys
from collections import deque
from html.parser import HTMLParser
from urllib.parse import urldefrag, urljoin, urlparse
from urllib.request import Request, urlopen
from urllib.robotparser import RobotFileParser

AGENT = "tiny-spider"


class Links(HTMLParser):
    def __init__(self):
        super().__init__()
        self.found = []

    def handle_starttag(self, tag, attrs):
        if tag == "a":
            self.found += [v for k, v in attrs if k == "href" and v]


start = sys.argv[1]
host = urlparse(start).netloc
robots = RobotFileParser(urljoin(start, "/robots.txt"))
robots.read()

frontier, seen = deque([start]), {start}
while frontier:
    url = frontier.popleft()
    if not robots.can_fetch(AGENT, url):
        print("skip ", url)
        continue
    with urlopen(Request(url, headers={"User-Agent": AGENT})) as page:
        parser = Links()
        parser.feed(page.read().decode("utf-8", "replace"))
    print("fetch", url)
    for href in parser.found:
        link = urldefrag(urljoin(url, href)).url
        if urlparse(link).netloc == host and link not in seen:
            seen.add(link)
            frontier.append(link)
```

On 2026-11-20 we ran it against a practice site of five pages, served from the same machine with `python3 -m http.server`. The home page links to an about page, a docs page and a page on another host. The docs page links to a guide, to the about page again, and to a page under `/private/`. The site’s robots.txt disallows `/private/`.

```bash
python3 tiny_spider.py http://127.0.0.1:8000/
```

```text
fetch http://127.0.0.1:8000/
fetch http://127.0.0.1:8000/about.html
fetch http://127.0.0.1:8000/docs.html
fetch http://127.0.0.1:8000/guide.html
skip  http://127.0.0.1:8000/private/notes.html
```

The spider fetched four pages and skipped the fifth because robots.txt told it to. It fetched the about page once, although two pages link to it. It did not request the page on the other host. The server’s log showed five requests: robots.txt and the four pages.

A production spider is built around the same loop. What the sketch leaves out is most of the work in a real one. It does not wait between requests, retry a failed page or follow a sitemap. It fetches one page at a time. It reads links from the HTML the server sends, so it misses links that a page builds with JavaScript. Run it on a site you own.

## Where did web spiders come from?

The first spiders date from 1993 and 1994, and the file that tells them where not to go dates from 1994 too.

| Year | What happened                                                                                                            | Source                                                                                      |
| ---- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------- |
| 1993 | Matthew Gray at MIT deployed the World Wide Web Wanderer, a crawler written in Perl, to measure the size of the web      | [Wikipedia, World Wide Web Wanderer](https://en.wikipedia.org/wiki/World_Wide_Web_Wanderer) |
| 1994 | Lycos began as a research project at Carnegie Mellon University. Its name is short for Lycosidae, the wolf spider family | [Wikipedia, Lycos](https://en.wikipedia.org/wiki/Lycos)                                     |
| 1994 | Martijn Koster defined the Robots Exclusion Protocol, the robots.txt file                                                | [RFC 9309](https://www.rfc-editor.org/rfc/rfc9309.html)                                     |
| 2022 | The IETF published the protocol as a standard, RFC 9309                                                                  | [RFC 9309](https://www.rfc-editor.org/rfc/rfc9309.html)                                     |

Both Wikipedia pages were read on 2026-11-20.

## What is robots.txt, and does a spider have to follow it?

robots.txt is a text file at the top of a site, at `/robots.txt`, that tells spiders which paths to leave alone. A spider that follows the protocol reads the file before it fetches anything else, as the sketch above does.

The file is a request. RFC 9309 says its rules “are not a form of access authorization”, so a site that needs to keep a page private has to protect it another way. The major search engine spiders follow the file, and a spider you write should too. Spider’s API follows it unless you change the setting. `respect_robots` defaults to true.

## Is a spider the same as a crawler or a scraper?

A spider and a crawler are the same program under two names. A scraper is different. A spider finds pages, and a scraper takes data out of a page it has been given, such as a price, a table or the article text. Most tools do both, which is why the two words get mixed up.

## Is Spider a web spider?

Yes. Spider is the web crawling and scraping company at spider.cloud, named for the programs that crawl the web. It makes one. `spider` is an open source web crawler written in Rust, published under the MIT license at [github.com/spider-rs/spider](https://github.com/spider-rs/spider). The Spider API runs the same kind of crawl as a service. You send a URL, and each page comes back as markdown or JSON. In a run on 2026-11-16, one crawl call returned 74 pages of a documentation site as markdown in 5.1 seconds.

That run, the requests in each language and the modes for pages that need a browser are on the [web crawling and scraping](/web-crawling-and-scraping/) page.
