Skip to main content

How to scrape a website, step by step

How to scrape a website, from reading robots.txt to saving a crawl one page at a time, with the curl command for each step and what it returned.

Updated 9 min read

To scrape a website, read its robots.txt, fetch a page, pull the text or fields you need, then crawl and save the rest. That comes to six steps, each with one command, in the order to run them, for someone who has never scraped a page.

I ran all six through the Spider API on November 17, 2026, against scrapethissite.com, a public site built for scraping practice. The crawl in step five returned 25 pages in 5.82 seconds. In step two a browser returned all 16 films from a page that builds its table with a script. Step three needs no key at all, and the web scraper sends a keyless request like it from your browser. Cost varies by site. On this one the crawl cost $0.0019, and the six requests sent with a key cost $0.0045 together.

Every step ends with the decision it settles. The web scraping guide explains why each step works.

What each step returned

StepWhat you sendWhat came back
5. Crawl the site/crawl with "limit": 2525 pages, in 5.82 s for $0.0019
6. Save as it arrives/crawl as JSON lines25 lines, in 8.12 s for $0.0019
1. Read robots.txt/scrape with "return_format": "raw"Three lines, in 0.86 s for $0.000002
2. Pick the fetch/scrape with "request": "browser"All 16 films, in 4.38 s for $0.000359
3. Scrape one page/scrape with no keyStatus 200 and 22,492 characters of markdown
4. Name the fields/scrape with css_extraction_mapThree lists of 250 values, in 1.55 s for $0.000318

All of these went out on the morning of November 17, 2026. The table opens with the two crawls, and the steps below go in number order. Seconds are wall time at the client. Cost is the costs.total_cost field on the pay as you go meter, summed over the 25 pages for each crawl, and it covers the requests sent with a key.

Step 1. Read the site’s robots.txt

curl -s https://www.scrapethissite.com/robots.txt

The practice site’s file is three lines:

User-agent: *
Disallow: /lessons/
Disallow: /faq/

The User-agent: * group is for every crawler the file does not name in a group of its own, and this file names none. Its two Disallow lines ask every crawler to skip the paths that start with /lessons/ or /faq/. The format is RFC 9309. Some files also carry a Crawl-delay line that asks for a pause between requests. It is not part of the RFC.

You can fetch the file straight from the site, as above, with no key. I fetched it through the API like every other request here, with a /scrape request for that URL and "return_format": "raw". It took 0.86 seconds and cost $0.000002.

The decision is whether to go on. Here the pages under /pages/ are open, so I went on. If the path you want is disallowed for all agents, pick another source. Our robots.txt survey of top sites shows what large sites ask for.

Step 2. Check the page source for the text

Open the page in your browser and press Ctrl+U, or Cmd+Option+U on a Mac, to see the HTML the server sent. Search it for a sentence you can see on the page.

The countries page in steps three and four passes this check. Its 250 country names are in the source, and a plain HTTP fetch returned all 250 of them. If the sentence is missing, a script most likely adds it after the page loads, and a browser that runs the script is the thing to try. The decision is the value of one field, "request": "http" or "request": "browser".

The practice site has a page of Oscar winning films that loads its table with a script, so its source holds the table header and no rows. That makes it a page for the browser. This request needs a key in SPIDER_API_KEY, as steps four to six do.

curl -X POST https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.scrapethissite.com/pages/ajax-javascript/#2015", "return_format": "markdown", "request": "browser"}'

The browser returned all 16 films in 4.38 seconds for $0.000359. The same page with "request": "http" took 1.11 seconds and cost $0.000033, and it returned what the source holds, the table header without the films. Both answers had status 200, so the status does not tell you which fetch a page needs. The source does.

Keep "http" for pages whose text is in the source, since it is the faster and cheaper fetch, and set "browser" when your own check says the text is missing. The plain fetch against browser measurement has numbers for more pages by kind.

Step 3. Scrape one page as markdown

curl -X POST https://api.spider.cloud/scrape \
  -H "Authorization: Bearer free" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.scrapethissite.com/pages/simple/", "return_format": "markdown", "request": "http"}'

Bearer free is the free tier, not a key. Without any Authorization header, /scrape now answers 402 with an x402 payment challenge. On November 17, 2026 it did not need the header, so my run left it out.

The answer is a JSON array with one object per page. content holds the markdown, status the HTTP status the site returned, and costs.total_cost what the request cost. This page lists 250 countries, and the request came back with status 200 and 22,492 characters of markdown. Read the markdown and check that a sentence you can see on the page is in it.

Keyless access is /scrape only and needs no account. Send Authorization: Bearer free. It is rate limited. On a 429, honor Retry-After. Get a key for anything sustained.

Markdown is a good default when a person or a model reads the text next. On ten public pages measured on November 5, 2026, markdown used 15 times fewer tokens than raw HTML at the median, as the token cost post shows. Ask for "raw" when you need the HTML itself.

Step 4. Extract fields with CSS selectors

When you want a name or a number instead of the whole page, give each field a name and a CSS selector. To find a selector, right click a country name on the countries page and choose Inspect. Each name carries the class country-name, so its selector is .country-name.

curl -X POST https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.scrapethissite.com/pages/simple/",
    "return_format": "markdown",
    "request": "http",
    "css_extraction_map": {
      "/": [
        { "name": "country", "selectors": [".country-name"] },
        { "name": "capital", "selectors": [".country-capital"] },
        { "name": "population", "selectors": [".country-population"] }
      ]
    }
  }'

Each name comes back as a list under css_extracted, because a selector can match more than once. This request took 1.55 seconds and cost $0.000318. Each of the three lists held 250 values, and the first of each was Andorra, Andorra la Vella and 84000.

I keyed the map by "/", which the API reference says matches every page. It also says any other key matches only the page whose path is exactly that key, and that a prefix such as "/products" currently matches nothing. Start with "/".

The decision here is whether you need fields at all. If the next step is a person reading or a model answering questions, the markdown from step three is enough.

Step 5. Crawl the site with a page limit

curl -X POST https://api.spider.cloud/crawl \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.scrapethissite.com/pages/", "limit": 25, "return_format": "markdown"}'

limit is the most pages the crawl returns. Set it on every crawl. Start at 25, read what came back, then raise it. depth caps how many links deep the crawl goes from the first page, 25 by default.

This crawl returned 25 pages in 5.82 seconds for $0.0019. Each page carries its own status, so read the statuses before the content. The practice site answers its login exercise, /pages/advanced/?gotcha=login, with status 400 and the text “Needs login”, and the crawl passed that status through with the page. As the API reference puts it, an attempt bills for the bandwidth and compute it used, whatever status the page returns.

The site’s menu links to /lessons/ and /faq/, the two paths its robots.txt disallows, and none of the 25 pages came from either. respect_robots is true by default, so a crawl skips the paths a site disallows.

Before you raise the limit, know the bill. On the pay as you go meter this crawl cost $0.0019 for 25 pages of a practice site. Budget from $0.16 per 1,000 pages, the lightest pages in the pricing guide. Cost varies by site. In a daily run from November 6 to 17, 2026, documentation pages cost $0.275 per 1,000 at the twelve-day median and articles $0.330 on the same meter. The Unlimited plan is priced by requests at once and not by page, from $40 a month for 2 in http mode. Read costs.total_cost on a small crawl first.

Step 6. Save each page as it arrives

curl -X POST https://api.spider.cloud/crawl \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/jsonl" \
  -d '{"url": "https://www.scrapethissite.com/pages/", "limit": 25, "return_format": "markdown"}' \
  -o pages.jsonl

The body is the same JSON as in step five. The Content-Type: application/jsonl header is how the API reference has you ask for JSON lines. The answer is one JSON object per line, one line per page. My file ended with 25 lines after 8.12 seconds, and the crawl cost $0.0019, the same as step five to four decimal places.

The reference says the answer streams as pages finish. Each line has the same url, status and content fields as the answer in step three, so any language can read the file one line at a time.

One crawl is one request to the API. If a script of yours sends many requests and gets a 429, wait the number of seconds in the Retry-After header, then send the request again.

Run the six steps on your own site

The six steps ran in one pass on one morning against one small practice site, and they do not cover logins, forms, infinite scroll or clicks. To run steps two and four to six, create an API key and export it as SPIDER_API_KEY.

Frequently asked questions

How do I scrape a website step by step?

Six steps. Read the site's robots.txt. Open the page source and look for the text you want, which tells you whether to try a plain fetch or a browser. Send one scrape request and read the markdown. Name the fields you want by CSS selector. Crawl the site with a page limit. Save each page as it arrives. Step three needs no API key. On November 17, 2026 the crawl in step five returned 25 pages from a practice site in 5.82 seconds for $0.0019.

Can I scrape a website without an API key?

Yes. Keyless access is /scrape only and needs no account. Send Authorization: Bearer free. It is rate limited. On a 429, honor Retry-After. Get a key for anything sustained. The curl in step three on this page sends that keyless request, and on November 17, 2026 it returned status 200 and 22,492 characters of markdown.

How much does it cost to scrape a website?

From $0.16 per 1,000 pages. Cost varies by site. The 25 page crawl of a practice site in step five cost $0.0019. The six requests on this page sent with a key cost $0.0045 together. The Unlimited plan is priced by requests at once and not by page, from $40 a month for 2 in http mode.

How do I know if a page needs a browser to scrape?

Open the page source and search for a sentence you can see on the page. If it is missing, a script most likely adds it after the page loads, so send the request with request set to browser. On the practice page in step two the source holds the table header and no rows, and a browser fetch on November 17, 2026 returned all 16 films.

Does the crawler follow robots.txt?

Yes, by default. The respect_robots option of the Spider API defaults to true in the OpenAPI file we read on November 16, 2026. In the crawl on this page, the practice site's menu links to /lessons/ and /faq/, its robots.txt disallows both, and none of the 25 pages returned was under either path.

Sources

  1. Measured run, 2026-11-17, 10:31:50 to 10:32:47 UTC: the requests on this page through the Spider API to www.scrapethissite.com, one each. The robots.txt fetch, a plain and a browser fetch of the films page, the keyless scrape, the fields scrape and the two crawls
  2. Spider OpenAPI file, read 2026-11-16: the request values, respect_robots default, css_extraction_map key matching, limit, depth, the application/jsonl content type, the keyless access note and the note on billing for failed pages
  3. Web scraping at scale: cost per 1,000 pages by kind of site, for its daily run from 2026-11-06 to 2026-11-17
  4. Spider pricing guide, what pages cost: light static pages from $0.16 per 1,000, measured 2026-11-17 on 25 catalogue pages of a practice site with the cache off
  5. Spider pricing page, the Unlimited plan's price by requests at once
  6. What a web page costs in tokens, measured on ten public pages, 2026-11-05
  7. How web scraping works: what a plain fetch gets and misses, measured 2026-11-16
  8. RFC 9309, the Robots Exclusion Protocol

Keep reading

Run this on a page you care about

The playground sends the request this page describes and shows you the response. Keyless runs work without an account and are rate limited.