24/28
Part 6 of 6 · What interviewers ask nextLearn and do

robots.txt: the site's rules for crawlers

A polite crawler also reads a site's rules before it fetches.

from urllib.robotparser import RobotFileParser

robots = RobotFileParser()
robots.parse(["User-agent: *", "Disallow: /private/", "Crawl-delay: 2"])
print(robots.can_fetch("mybot", "http://example.com/private/x"))
print(robots.can_fetch("mybot", "http://example.com/docs"))
print(robots.crawl_delay("mybot"))
Predict

robots.txt says Disallow: /private/ and Crawl-delay: 2. What do the three lines print?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

Which failure should you not retry?

Pick an answer above to see the rest