======= Protego
.. image:: https://img.shields.io/pypi/pyversions/protego.svg :target: https://pypi.python.org/pypi/protego :alt: Supported Python Versions
.. image:: https://img.shields.io/travis/scrapy/protego/master.svg :target: https://travis-ci.org/scrapy/protego :alt: Build Status
Protego is a pure-Python robots.txt parser with support for modern
conventions.
Install
To install Protego, simply use pip:
.. code-block:: none
pip install protego
Usage
from protego import Protego robotstxt = """ ... User-agent: * ... Disallow: / ... Allow: /about ... Allow: /account ... Disallow: /account/contact$ ... Disallow: /account/*/profile ... Crawl-delay: 4 ... Request-rate: 10/1m # 10 requests every 1 minute ... ... Sitemap: http://example.com/sitemap-index.xml ... Host: http://example.co.in ... """ rp = Protego.parse(robotstxt) rp.can_fetch("http://example.com/profiles", "mybot") False rp.can_fetch("http://example.com/about", "mybot") True rp.can_fetch("http://example.com/account", "mybot") True rp.can_fetch("http://example.com/account/myuser/profile", "mybot") False rp.can_fetch("http://example.com/account/contact", "mybot") False rp.crawl_delay("mybot") 4.0 rp.request_rate("mybot") RequestRate(requests=10, seconds=60, start_time=None, end_time=None) list(rp.sitemaps) ['http://example.com/sitemap-index.xml'] rp.preferred_host 'http://example.co.in'
Using Protego with Requests_:
from protego import Protego import requests r = requests.get("https://google.com/robots.txt") rp = Protego.parse(r.text) rp.can_fetch("https://google.com/search", "mybot") False rp.can_fetch("https://google.com/search/about", "mybot") True list(rp.sitemaps) ['https://www.google.com/sitemap.xml']
.. _Requests: https://3.python-requests.org/
Comparison
The following table compares Protego to the most popular robots.txt parsers
implemented in Python or featuring Python bindings:
+----------------------------+---------+-----------------+--------+---------------------------+
| | Protego | RobotFileParser | Reppy | Robotexclusionrulesparser |
+============================+=========+=================+========+===========================+
| Implementation language | Python | Python | C++ | Python |
+----------------------------+---------+-----------------+--------+---------------------------+
| Reference specification | Google_ | Martijn Koster’s 1996 draft_ |
+----------------------------+---------+-----------------+--------+---------------------------+
| Wildcard support_ | ✓ | | ✓ | ✓ |
+----------------------------+---------+-----------------+--------+---------------------------+
| Length-based precedence_ | ✓ | | ✓ | |
+----------------------------+---------+-----------------+--------+---------------------------+
| Performance_ | | +40% | +1300% | -25% |
+----------------------------+---------+-----------------+--------+---------------------------+
.. _Google: https://developers.google.com/search/reference/robots_txt .. _Length-based precedence: https://developers.google.com/search/reference/robots_txt#order-of-precedence-for-group-member-lines .. _Martijn Koster’s 1996 draft: https://www.robotstxt.org/norobots-rfc.txt .. _Performance: https://anubhavp28.github.io/gsoc-weekly-checkin-12/ .. _Wildcard support: https://developers.google.com/search/reference/robots_txt#url-matching-based-on-path-values
API Reference
Class protego.Protego:
Properties
-
sitemaps{list_iterator} A list of sitemaps specified inrobots.txt. -
preferred_host{string} Preferred host specified inrobots.txt.
Methods
-
parse(robotstxt_body)Parserobots.txtand return a new instance ofprotego.Protego. -
can_fetch(url, user_agent)Return True if the user agent can fetch the URL, otherwise returnFalse. -
crawl_delay(user_agent)Return the crawl delay specified for the user agent as a float. If nothing is specified, returnNone. -
request_rate(user_agent)Return the request rate specified for the user agent as a named tupleRequestRate(requests, seconds, start_time, end_time). If nothing is specified, returnNone.
Metadata
Release files for Protego 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Protego-0.2.0.tar.gz | 3.2 MB | Without provenance | Details for Protego-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Protego-0.2.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for Protego-0.2.0-py2.py3-none-any.whl |
Total release size: 3.3 MB
Release files / Protego-0.2.0.tar.gz
| Download URL | Protego-0.2.0.tar.gz |
|---|---|
| Size | 3.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b99605617a42ce07b049e0b9d6dc3ee5efb9924f26fd115eaafbc8f9a37470e
|
|
BLAKE2b-256 checksum How to use checksums |
aafbdd1e88dd52b1fdcc2dc24f4f3618927b57f3232dcaa478ee6c4e9e5022aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10
|
Release files / Protego-0.2.0-py2.py3-none-any.whl
| Download URL | Protego-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
cd4e4f2a0a27471bcc26ddbfcab9744fa24b998b8c446fe0b2427c2e07348048
|
|
BLAKE2b-256 checksum How to use checksums |
bd89c6b1065f70e7d55a13ef29322d30a2966af3090c5fa33027b389d5d1fe49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10
|
Security for Protego 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.