courlan.urlstore¶
Domain-classified URL storage for web crawling workflows.
For usage examples, see the URL Store guide and the Web Crawling guide.
Defines a URL store which holds URLs along with relevant information and entails crawling helpers.
- class courlan.urlstore.Compressor(compression=True)[source]¶
Bases:
objectUse system information on available compression modules and define corresponding methods.
- Parameters:
compression (bool)
- class courlan.urlstore.DomainEntry(state=State.OPEN)[source]¶
Bases:
objectClass to record host-related information and URL paths.
- Parameters:
state (State)
- rules: bytes | RobotFileParser | None¶
- tuples: bytes | deque[UrlPathTuple]¶
- class courlan.urlstore.State(*values)[source]¶
Bases:
EnumRecord state information about a domain or host.
- ALL_VISITED = 2¶
- BUSTED = 3¶
- OPEN = 1¶
- class courlan.urlstore.UrlPathTuple(urlpath, visited)[source]¶
Bases:
objectClass storing information for URL paths relative to a domain/host.
- class courlan.urlstore.UrlStore(compressed=False, language=None, strict=False, trailing_slash=True, verbose=False)[source]¶
Bases:
objectDefines a class to store domain-classified URLs and perform checks against it.
Thread-safety: readers are safe and writers are serialized, but a logical write is not globally atomic — drive mutations from a single writer thread.
- Parameters:
- add_from_html(htmlstring, url, external=False, lang=None, with_nav=True)[source]¶
Find links in a HTML document, filter them and add them to the data store.
- add_urls(urls=None, appendleft=None, visited=False)[source]¶
Add a list of URLs to the (possibly) existing one. Optional: append certain URLs to the left, specify if the URLs have already been visited.
- download_threshold_reached(threshold)[source]¶
Find out if the download threshold (number of retrieved URLs) has been reached for one of the websites in store.
- establish_download_schedule(max_urls=100, time_limit=10)[source]¶
Get up to the specified number of URLs along with a suitable backoff schedule (in seconds).
- find_known_urls(domain)[source]¶
Get all already known URLs for the given domain (ex. “https://example.org”).
- get_crawl_delay(website, default=5)[source]¶
Return the delay as extracted from robots.txt, or a given default.
- get_download_urls(time_limit=10.0, max_urls=10000)[source]¶
Get a list of immediately downloadable URLs according to the given time limit per domain.
- get_rules(website)[source]¶
Return the stored crawling rules for the given website.
- Parameters:
website (str)
- Return type:
RobotFileParser | None
- get_unvisited_domains()[source]¶
Find all domains for which there are unvisited URLs and potentially adjust done meta-information.
- get_url(domain, as_visited=True)[source]¶
Retrieve a single URL and consider it to be visited (with corresponding timestamp).
- store_rules(website, rules)[source]¶
Store crawling rules for a given website.
- Parameters:
website (str)
rules (RobotFileParser | None)
- Return type:
None
- unvisited_websites_number()[source]¶
Return the number of websites for which there are still URLs to visit.
- Return type:
- urldict: defaultdict[str, DomainEntry]¶