Skip to main content

Your first request: fetch one page and read the answer

A scraper starts with one HTTP request. What goes out, what comes back, and how to read the status code before you trust the page.

From our run on
  1. "url": "https://example.com/",
  2. "status": 200,
  3. "error": null
Lesson 1 of 20 5 min read

Every scraper starts by sending one HTTP GET request to one address and reading the response that comes back. The response has a status code, headers and a body, and the status code tells you whether the body is the page you asked for.

This lesson sends that request twice, first with curl and then through an API, and reads each part of the answer. It is lesson 1 of the course, and the course is one part of the web scraping guide.

What goes out

curl -i https://example.com/

The -i flag prints the status line and the headers above the body. Run it and keep the output on screen.

curl sent a small message for you. It holds the method, GET, the path, /, the name of the host and a few headers. RFC 9110, the standard that defines HTTP's methods and status codes, describes GET in one line: "The GET method requests transfer of a current selected representation for the target resource." In plain words, send me this page as it is now.

One of those headers is User-Agent, and it says who is calling. The standard asks for it: "A user agent SHOULD send a User-Agent header field in each request unless specifically configured not to do so." curl sends its own name and version. A scraper you write should send a name of its own, so the site's owner can tell your requests apart from everyone else's.

This clip reads the answer field by field.

Your first request. 48 s, no sound. The words are on screen, and the captions button shows them at your own text size.
Read the transcript

Your first request. One address sent, one object back, read field by field.

The request is one JSON body with three fields. "url": "https://example.com": the page to fetch. "request": "http": how to fetch it. "return_format": "markdown": the form of the answer. 3: fields sent. 1: page asked for.

One object comes back for the page, with four fields. url: https://example.com/. status: 200. content, line 1: Example Domain. error: null. 4: fields in the answer. 2: lines of text in content. 171: characters in content.

A status alone is not the check. Look for text you expect. "Example Domain", the text that must appear. times in content: 1. status: 200. status class: 2xx. 2: lines of content searched. 171: characters in them.

The first digit of the status says what to do next. Read the status class: the page's own status. 2xx: Read the body. 3xx: Follow the Location header. 4xx: Fix the request. 5xx: Wait, then try again. This run: 2xx.

Read the full page. The page is at spider.cloud/learn/course/your-first-request.

What comes back

The response has three parts, and you read them in this order.

The status code comes first. RFC 9110 calls it "a three-digit integer code that describes the result of the request". The first digit sorts every code into a class, and the class tells you what to do next.

ClassRFC 9110 describes it asWhat a scraper does
2xx"The request was successfully received, understood, and accepted"Read the body.
3xx"Further action needs to be taken" before the request is completeFollow the Location header to the new address.
4xx"The request contains bad syntax or cannot be fulfilled"Fix the request. Sending the same one again gets the same answer. Two codes are exceptions: 429 and 408 ask you to wait, then try again.
5xx"The server failed to fulfill an apparently valid request"Wait, then try again.

The headers come second. They describe the body and sometimes tell you how to behave. Content-Type says what kind of document the body is. Retry-After appears when the server wants you to slow down, and RFC 9110 says servers send it "to indicate how long the user agent ought to wait before making a follow-up request." When you see it, wait that long.

The body comes last. It is the document itself, most often HTML.

Check the body before you trust it

A 200 is not proof that you got the page you wanted. RFC 9110 defines it narrowly: "The 200 (OK) status code indicates that the request has succeeded." The request succeeded. The body can still be a sign-in form, a notice that the page has moved, or an error page sent with the wrong code.

So add one check of your own. Before you run the request, choose a word that must appear on the real page, such as a product name or a heading. After the response arrives, look for it. If the word is missing, treat the page as failed, whatever the status code says.

The same request through an API

A scraping API sends the request from its own servers and returns the page in the format you choose. This request asks the Spider API for the same page as markdown. It needs an API key in SPIDER_API_KEY. You can create an API key, or paste a URL into the web scraper to read an answer before you have one.

curl -s https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com", "request": "http", "return_format": "markdown"}'

The answer is a JSON array with one object per page. Four fields matter for this lesson.

FieldWhat it holds
urlThe address that was fetched
statusThe page's own HTTP status
contentThe page in the return_format you asked for
errorWhy the page failed, or null

Read status before content, as you did with curl. There are two status codes in play here. The HTTP status of your call to the API says whether the API did its job, and the status field says what the site answered. The API reference puts it this way: "A 200 from the API can carry a page with status 404."

We sent that request on 2026-11-20 at 14:17 UTC. The call answered 200, and these are the four fields of the one object it returned.

{
  "url": "https://example.com/",
  "status": 200,
  "content": "Example Domain\nThis domain is for use in documentation examples without needing permission. This is not a service; avoid relying on it for testing and monitoring purposes.",
  "error": null
}

The check from the last section works here too. "Example Domain" is the word that must appear, and it does.

Try it yourself

Pick a page you read often, such as a documentation page, and send it the same two requests: curl -i first, then the API call with your page's address in url. Before you look at either answer, choose one word that must be on the real page. You are done when you can say which status code each request returned and whether your word is in the content field.

Do this, avoid this

Do this

  • Read the status code before the body.
  • Send a User-Agent header that names your client.
  • Wait as long as Retry-After says before you ask again.
  • Check the body for a word you expect to find.
  • Get one page right before you fetch a second.

Avoid this

  • Parsing a body without looking at its status.
  • Sending a 4xx request again without changing it, unless the code is 429 or 408.
  • Retrying a 5xx in a tight loop.
  • Taking a 200 as proof that you got the page you wanted.

Before you fetch a second page

One request to one page is a polite amount of traffic. A second page from the same site is where manners start to matter. Before you send it, read what robots.txt is and how a well-behaved client reads it. It is the file where the site tells you which pages it wants left alone.

Sources

  1. RFC 9110, HTTP Semantics, IETF, June 2022 Read
  2. Spider OpenAPI file, the /scrape request and the url, content, status and error fields of a page result Read

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.