roboter

2026-11-29

An implementation of the RFC 9309 Robots Exclusion Protocol for parsing robots.txt files

Upstream URL

codeberg.org/Andrei/roboter

Author

Andrei Șova

License

MIT
README

1Roboter

Roboter is a simple parser for "robots.txt" files, which define policy for use with web scrapers. It is, to my knowledge, a correct implementation of RFC 9309, and it is also quite flexible. If you use Roboter in your own projects and find any issues with the implementation, I would love to hear from you.

It should work on SBCL, ECL, ABCL, CLISP, and pretty much any conformant implementation.

1.1Usage

The interface is located inside of the org.rm-r.roboter package. There is alsoa nickname roboter which I will use for brevity:

1.1.1Install using quicklisp

If you have the ultralisp dist installed, you can do:

  (ql:quickload :roboter)

1.1.2Parsing a robots.txt file

We can pass in any string to parse, which will return a policy object.
  (defparameter *site-policy*
    (roboter:parse (dex:get "https://example.com/robots.txt")))

Note that this is often a bad idea, as robots.txt files in the wild can often have strange encodings such as BOM, or can sometimes be intentionally (maliciously) huge. You should at least remove any BOM bytes and check that it is not excessively large. The way this is done can potentially depend on your Common Lisp implementation. Maybe I will create a new library that does this in the future.

parse can also take in the key argument global-rules. This is a list that defaults to ='("sitemap")=, and it determines which robots.txt directives are parsed globally instead of being tied to a specific user-agent.

1.1.3Querying a policy object

You can then query the policy object:

(roboter:allowed-p *site-policy* "Yandex" "/foo.html")

This will return T if and only if the policy indicates that the scraper with the given user agent (in this case, "Yandex") can access the given path. Note that as per the standard, the user agent is case insensitive. This should suffice for most use-cases.

You can also get more data from the policy object, such as specific values of certain rules:

(roboter:policy-query *site-policy* "sitemap")

This will return a list of strings which are the values of the given rule. Alternatively if you want to query a rule tied to a user-agent, you can pass in the user-agent:

(roboter:policy-query *site-policy* "crawl-delay" "Googlebot")

1.2Areas of improvement

Code coverage is rather lacking.

Dependencies (2)

  • babel
  • rove

Dependents (0)

    • GitHub
    • Quicklisp