MCPcopy Create free account
hub / github.com/apify/crawlee-python / get_sitemaps

Method get_sitemaps

src/crawlee/_utils/robots.py:98–116  ·  view source on GitHub ↗

Get the list of sitemap URLs from the robots.txt file, filtered by enqueue strategy. Args: enqueue_strategy: Strategy used to filter sitemap entries relative to the robots.txt URL's host. Pass `'same-hostname'` to match the sitemap protocol's same-host expectatio

(self, *, enqueue_strategy: EnqueueStrategy)

Source from the content-addressed store, hash-verified

96 return bool(self._robots.can_fetch(str(check_url), user_agent))
97
98 def get_sitemaps(self, *, enqueue_strategy: EnqueueStrategy) -> list[str]:
99 """Get the list of sitemap URLs from the robots.txt file, filtered by enqueue strategy.
100
101 Args:
102 enqueue_strategy: Strategy used to filter sitemap entries relative to the robots.txt URL's host.
103 Pass `'same-hostname'` to match the sitemap protocol's same-host expectation, or `'all'` to
104 disable host filtering. Regardless of the strategy, entries with non-`http(s)` schemes are
105 always filtered out.
106 """
107 sitemaps: list[str] = []
108 for sitemap_url in self._robots.sitemaps:
109 ok, reason = filter_url(target=sitemap_url, strategy=enqueue_strategy, origin=self._original_url)
110 if not ok:
111 logger.warning(
112 f'Skipping sitemap {sitemap_url!r} listed in robots.txt at {str(self._original_url)!r}: {reason}.'
113 )
114 continue
115 sitemaps.append(sitemap_url)
116 return sitemaps
117
118 def get_crawl_delay(self, user_agent: str = '*') -> int | None:
119 """Get the crawl delay for the given user agent.

Calls 1

filter_urlFunction · 0.90