Skip to main content
Version: Next

ExtractLinksFunction

A function for extracting URLs to crawl based on elements selected by a given selector.

It extracts URLs from the current page and allows filtering through selectors and other options. You can also specify labels and user data to be associated with the newly created Request objects.

Index

Methods

Methods

__call__

  • __call__(*, selector, attribute, label, user_data, transform_request_function, limit, base_url, strategy, include, exclude): Coroutine[None, None, list[Request]]
  • Call extract links function.


    Parameters

    • optionalkeyword-onlyselector: str = 'a'

      A selector used to find the elements containing the links. The behaviour differs based on the crawler used:

      • PlaywrightCrawler supports CSS and XPath selectors.
      • ParselCrawler supports CSS selectors.
      • BeautifulSoupCrawler supports CSS selectors.
    • optionalkeyword-onlyattribute: str = 'href'

      Which node attribute to extract the links from.

    • optionalkeyword-onlylabel: str | None = None

      Label for the newly created Request objects, used for request routing.

    • optionalkeyword-onlyuser_data: Mapping[str, JsonSerializable] | None = None

      User data to be provided to the newly created Request objects.

    • optionalkeyword-onlytransform_request_function: Callable[[RequestOptions], RequestOptions | RequestTransformAction] | None = None

      A function that takes RequestOptions and returns either:

      • Modified RequestOptions to update the request configuration,
      • 'skip' to exclude the request from being enqueued,
      • 'unchanged' to use the original request options without modification.
    • keyword-onlyoptionallimit: int

      Maximum number of requests to be enqueued.

    • keyword-onlyoptionalbase_url: str

      Base URL to be used for relative URLs.

    • keyword-onlyoptionalstrategy: EnqueueStrategy

      Enqueue strategy that determines which URLs are enqueued based on their relation to the page the crawler is currently on. With enqueue_links it filters the links extracted from the page. With add_requests it filters the explicitly provided requests.

      Options: all: Enqueue every URL encountered, regardless of the target domain. Use this option to ensure that all URLs, including those leading to external websites, are followed. same-domain: Enqueue URLs that share the same domain name as the current page, including any subdomains. This strategy is ideal for crawling within the same top-level domain while still allowing for subdomain exploration. same-hostname: Enqueue URLs only if they match the exact hostname of the current page. This is the default for enqueue_links and restricts the crawl to the current hostname, excluding subdomains. same-origin: Enqueue URLs that share the same origin as the current page. The origin is defined by the combination of protocol, domain, and port, ensuring a strict scope for the crawl.

    • keyword-onlyoptionalinclude: Sequence[re.Pattern | Glob]

      List of regular expressions or globs that URLs must match to be enqueued.

    • keyword-onlyoptionalexclude: Sequence[re.Pattern | Glob]

      List of regular expressions or globs that URLs must not match to be enqueued.

    Returns Coroutine[None, None, list[Request]]

Page Options