robotto
Easily read, parse and check permissions on robots.txt files!
Installing
You can easily install robotto using npm. Just run:
npm install robotto
Getting Started
After installing robotto you need to require it using:
var robotto = ;
Now you can call every single robotto's methods using your robotto variable!
To check if a website allows you to crawl a certain url you just gotta call the canCrawl(userAgent, fullUrl, callback)
method. Take a look below for an example on how to do this:
var robotto = ; robotto;
Simple, isn't it?
Docs
Methods
robotto.getRobotsUrl(url)
Returns the full url to the website's robots.txt.
Parameters
- url -> Any url
Example
var robotsUrl = robotto;console;// --> http://www.007.com/robots.txt
robotto.fetch(url, callback)
Gets the content of the robots.txt file.
Parameters
- url -> Any url
- callback(err, content)
- err -> Errors, if any, otherwise
null
- content -> Content of the robots.txt file
- err -> Errors, if any, otherwise
Example
robotto;
robotto.parse(text)
Parses the content of a robots.txt file and returns an object with it's rules.
This is an example of the rules object returned:
comments: "This is a comment" "This is another comment" userAgents: Googlebot: allow: '/cats/' '/dogs/' disallow: '/sharks/' '/tigers/' Msnbot: allow: '/technology' disallow: '/whatever/' '/example/'
Parameters
- text -> The content of a robots.txt file
Example
robotto;
robotto.getRuleDeepness(ruleName, userAgent, urlParam, rulesObj)
Returns the deepness (precision) for a rule, because if an allow
and a disallow
rule conflict, the most specific is the one to be taken into account.
For example:
/
is disallowed/magical-route
is allowed
In this case we shouldn't be able to crawl any URL except the ones into /magical-route/
, because it's the most specific rule.
If the rule you requested is invalid it returns -1. If there isn't any rule for the url you want, it returns 0, otherwise it will return the deepness of the rule (number of parameters specified in robots.txt
).
Parameters
- ruleName -> A string containing
allow
ordisallow
- userAgent -> The user-agent's name
- url -> Any url
- rulesObject -> An object with rules
Example
robotto;
robotto.check(userAgent, url, rulesObject)
Checks if an user-agent has permission to crawl an url based on an object with rules. If there are contraditory rules the most specific will be considered.
Parameters
- userAgent -> The user-agent's name
- url -> Any url
- rulesObject -> An object with rules
Example
robotto;
robotto.canCrawl(userAgent, url, callback)
Checks if an user-agent has permission to crawl an url.
Parameters
- userAgent -> The name of your bot (your user-agent)
- url -> Any url
- callback(err, isAllowed)
- err -> Errors, if any, otherwise
null
- isAllowed -> Boolean value indicating if this user-agent is allowed to crawl the url
- err -> Errors, if any, otherwise
Example
robotto;
Contributing
Feel free to contribute in any way you want. Every help is valid. If you find any issues or even if you have a suggestion please feel free to report it using our issue tracker.
If you want to write some code follow these steps:
-
Clone this repo using:
$ git clone https://github.com/trachelas/robotto
-
Go to the folder in which you cloned the repo and install the dev-dependencies:
$ npm install
-
Write your code
-
Write tests for it (if needed)
-
Run
gulp build
and make sure all the tests pass and that you've got 100% code coverage. -
Open a new
pull-request
If you have any doubt please let us know. We'll do our best to explain every detail you need to know in order to contribute.
This is the OpenSource Software's magic ✨
Credits
Robotto is proudly brought to you by the Trachelas Team.
Name | Github | |
---|---|---|
Lucas F. da Costa | github.com/lucasfcosta | @lfernandescosta |
Lucas Vieira | github.com/vieiralucas |
License
No need for copyright, live free, buddy, internet is for everyone 😉