A survey of robots.txt - part one

After readingCollinMorris’s analysis of faviconsof the top 1 million sites on the web, I thought it would be interesting to do the same for other common parts of websites that often get overlooked.

Therobots.txtfile is a plain text file found at on most websites which communicates information to web crawlers and spiders about how to scan a website.. For example, here’s an excerpt fromrobots.txtforgoogle.com

1User-agent: *2Disallow: /search3Allow: /search/about4Allow: /search/howsearchworks5...

The above excerpt tells all web crawlers not to scan the/searchpath, but allows them to scan/search/aboutand/search/howsearchworkspaths. There are a few more supported keywords, but these are the most common. Following these instructions is not required, but it is considered good internet etiquette. If you want to read more about the standard, Wikipedia has a great pagehere.

In order to do an analysis ofrobots.txt, first I need to crawl the web for them – ironic, I know.

Scraping

I wrote a scraper usingscrapyto make a request forrobots.txtfor each of the domains in Alexa’s top 1 million websites. If the response code was 200, theContent-Typeheader containedtext/plain, and the response body was not empty, I stored the response body in a file, with the same name as the domain name.

One complication I encountered was that not all domains respond on the same protocol or subdomain. For example, some websites respond onhttp://{domain_name}while others requirehttp://www.{domain_name}. If a website doesn’t automatically redirect you to the correct protocol or subdomain, the only way to find the correct one, is to try them all! So I wrote a small class, extending scrapy’sRetryMiddleware, to do this:

1COMMON_PREFIXES={'http://','https://','http://www.','https://www.'}23classPrefixRetryMiddleware(RetryMiddleware):45defprocess_exception(self,request,exception,spider):6prefixes_tried=request.meta['prefixes']7ifCOMMON_PREFIXES==prefixes_tried:8returnexception910new_prefix=choice(tuple(COMMON_PREFIXES-prefixes_tried))11request=self.update_request(request,new_prefix)1213returnself._retry(request,exception,spider)

The rest of the scraper itself is quite simple, but you can read the full codeon GitHub.

Results

Scraping the full Alexa top 1 million websites list took around 24 hours. Once it was finished, I had just under 700k robots.txt files

1$ find -type f|wc -l2677686

totalling 493MB

1$ du -sh2493M .

The smallestrobots.txtwas 1 byte1, but the largest was over 5MB.

1$ find -type f -exec du -Sh{}+|sort -rh|head -n125.6M ./haberborsa.com.tr34$ find -not -empty -type f -exec du -b{}+|sort -h|head -n151./0434.cc

The full data set is released under theOpen Database License (ODbL) v1.0and can be foundon GitHub

What’s next?

In the next part of this blog series I’m going to analyse all therobots.txtto see if I can find anything interesting. In particular I’d like to know why exactly someone needs arobots.txtfile over 5MB in size, what is the most common web crawler listed (either allowed or disallowed), and are there any sites practising security by obscurity by trying to keep links out of search engines!


  1. I needed to include-not -emptywhen looking for the smallest file, as there were errors when decoding the response body for some domains. I’ve included the empty files in the dataset for posterity, but I will exclude them from further analysis. ↩︎