Answer key · 12 questions

Python robots.txt and polite scraping Exercises With Answers

All 12 questions for Python robots.txt and polite scraping in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python robots.txt and polite scraping, with the exact answer and a short explanation for every question.

The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.

01 · Multiple choice

What does Disallow: /private mean?

  1. The crawler must use a browser
  2. The path is encrypted
  3. Matching crawlers should not fetch paths under /privatecorrect
  4. The page is missing

Answer: Matching crawlers should not fetch paths under /private

Why: Disallow publishes a crawl preference for matching user agents.

02 · Multiple choice

Where is robots.txt normally published?

  1. Inside every HTML page
  2. In the sitemap only
  3. In the CSS folder
  4. At the site root, /robots.txtcorrect

Answer: At the site root, /robots.txt

Why: Crawlers look for /robots.txt at the root of the site.

03 · Multiple choice

What should a crawler do after a 429 response?

  1. Ignore the status and parse the page
  2. Retry immediately in a loop
  3. Slow down and retry latercorrect
  4. Change the URL to bypass the limit

Answer: Slow down and retry later

Why: 429 means too many requests; back off and respect Retry-After when provided.

04 · Multiple choice

Which action is appropriate for a public page?

  1. Bypass a login wall
  2. Collect only the needed public fields within site termscorrect
  3. Collect personal data without a basis
  4. Ignore robots.txt because the page loads

Answer: Collect only the needed public fields within site terms

Why: Public reachability does not remove terms, privacy, or crawl limits.

05 · Fill in the blank

Complete the directive that names the crawler group.

line = "____: *"
key = line.split(":", 1)[0]
print(key)

Answer: User-agent

Why: User-agent begins a group of rules for a named client.

06 · Fill in the blank

Complete the directive that blocks a path.

robots = "User-agent: *\nDisallow: /private"
for line in robots.splitlines():
    if line.startswith("____"):
        print(line)

Answer: Disallow

Why: Disallow marks paths that matching crawlers should not fetch.

07 · Fill in the blank

Complete the directive that sets a delay between requests.

key = "____"
print(key in {"User-agent", "Disallow", "Crawl-delay", "Sitemap"})

Answer: Crawl-delay

Why: Crawl-delay suggests a pause between requests for a crawler group.

08 · Fill in the blank

Complete the directive that points to a sitemap.

line = "____: https://example.com/sitemap.xml"
print(line.startswith("Sitemap"))

Answer: Sitemap

Why: Sitemap gives crawlers a URL for the site's sitemap.

09 · Predict output

What does this code print?

robots = "User-agent: *\nDisallow: /private\nCrawl-delay: 2"
rules = {}
for line in robots.splitlines():
    if ":" in line:
        key, value = line.split(":", 1)
        rules[key.strip().lower()] = value.strip()
print(rules["disallow"])

Answer: /private

Why: The Disallow value is /private.

10 · Predict output

What does the program output?

robots = "User-agent: *\nDisallow: /private\nCrawl-delay: 2"
rules = {}
for line in robots.splitlines():
    if ":" in line:
        key, value = line.split(":", 1)
        rules[key.strip().lower()] = value.strip()
print(rules["crawl-delay"])

Answer: 2

Why: The Crawl-delay value is the string 2.

11 · Predict output

What appears on the screen?

rules = [("allow", "/docs"), ("disallow", "/private")]
path = "/private/report"
decision = "allowed"
for kind, prefix in rules:
    if path.startswith(prefix):
        decision = kind
print(decision)

Answer: disallow

Why: The path matches the longer /private rule, so the decision becomes disallow.

12 · Predict output

What is printed?

record = {"name": "Ada", "email": "[email protected]", "bio": "Python"}
public = {key: value for key, value in record.items() if key != "email"}
print(public)

Answer: {'name': 'Ada', 'bio': 'Python'}

Why: The dictionary comprehension removes the email field.

Try the questions first

Open the practice page for Python robots.txt and polite scraping and answer the same 12 questions with instant feedback.

Practice this lesson