Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: RecursiveUrlLoader: add base_url option #19421

Merged
merged 6 commits into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def __init__(
headers: Optional[dict] = None,
check_response_status: bool = False,
continue_on_failure: bool = True,
*,
base_url: Optional[str] = None,
) -> None:
"""Initialize with URL to crawl and any subdirectories to exclude.

Expand All @@ -120,6 +122,7 @@ def __init__(
URLs with error responses (400-599).
continue_on_failure: If True, continue if getting or parsing a link raises
an exception. Otherwise, raise the exception.
base_url: The base url to check for outside links against.
"""

self.url = url
Expand All @@ -146,6 +149,7 @@ def __init__(
self.headers = headers
self.check_response_status = check_response_status
self.continue_on_failure = continue_on_failure
self.base_url = base_url if base_url is not None else url

def _get_child_links_recursive(
self, url: str, visited: Set[str], *, depth: int = 0
Expand Down Expand Up @@ -187,7 +191,7 @@ def _get_child_links_recursive(
sub_links = extract_sub_links(
response.text,
url,
base_url=self.url,
base_url=self.base_url,
pattern=self.link_regex,
prevent_outside=self.prevent_outside,
exclude_prefixes=self.exclude_dirs,
Expand Down Expand Up @@ -273,7 +277,7 @@ async def _async_get_child_links_recursive(
sub_links = extract_sub_links(
text,
url,
base_url=self.url,
base_url=self.base_url,
pattern=self.link_regex,
prevent_outside=self.prevent_outside,
exclude_prefixes=self.exclude_dirs,
Expand Down