Parse robots.txt
Project description
robotsparsetools
robots.txt is important when crawling website
This module will help you parse robots.txt
Install
$ pip install robotsparsetools
Usage
Parse
Please create an Parse instance first
from robotsparsetools import Parse
url = "URL of robots.txt you want to parse"
p = Parse(url) # Create an instance. Returns a Parse class with the useragent as the key
# Get allow list
p.Allow(useragent)
# Get disallow list
p.Disallow(useragent)
# Get value of Crawl-delay(Return value is int or None)
p.delay(useragent)
# Find out if crawls are allowed
p.can_crawl(url, useragent)
If no useragent is specified, the value of '*' will be referenced
Also, since the Parse class inherits from dict, you can also use it like dict
from robotsparsetools import Parse
p = Parse(url)
p["*"]
p.get("*") # Can also use get method
Read
You can parse its contents by passing a text or local path to Read
from robotsparsetools import Read
import requests
url = "URL of robots.txt you want to parse"
r = requests.get(url)
p = Read(r.text)
path = "File path of robots.txt you want to parse"
p = Read(path)
The return value is a Parse instance
Make(✨ new in 1.3)
You can easily generate the contents of robots.txt by using this
from robotsparsetools import Make
base = Make()
base.add_sitemap("https://xxxxxx.com/sitemap.xml")
all = base.add_useragent("*")
all.add_disallow("/hoge")
bot = base.add_useragent("bot")
bot.add_allow(["/example", "/any/*"])
bot.add_disallow(["/test", "/xxx/"])
path = "File path"
base.to_file(path) # Output the result to a file
print(base.make()) # Generation
Below is the result of this code
User-agent: *
Disallow: /hoge
User-agent: bot
Disallow: /test
Disallow: /xxx/
Allow: /example
Allow: /any/*
Sitemap: https://xxxxxx.com/sitemap.xml
Error Classes
Also, there are three error classes
from robotsparsetools import NotURLError, NotFoundError, UserAgentExistsError
License
This program's license is MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file robotsparsetools-1.3.2.tar.gz.
File metadata
- Download URL: robotsparsetools-1.3.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1d8e5d2dbb338d23849b3edd175db5e35ac0fa8c145a6f6a451498bcacecfc3
|
|
| MD5 |
346e3b568709e32b28c3644600be782b
|
|
| BLAKE2b-256 |
dc6899b70c77e07ce266976092d1c9a9877b4174cf588737f5a5f602de50ea7e
|
File details
Details for the file robotsparsetools-1.3.2-py3-none-any.whl.
File metadata
- Download URL: robotsparsetools-1.3.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
460b10a2f108b6696bb0082fa097ef2b81a3da9739f80e5f1b0855992d08a2af
|
|
| MD5 |
9f3b2fb616c20ec40e6e272b9ff6ae2a
|
|
| BLAKE2b-256 |
cf523d8e9ae49696c59433b46b0b121fbdd2072d5905272ffce54d401a65b4f6
|