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 3 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 @@ -83,6 +83,7 @@ class RecursiveUrlLoader(BaseLoader):
def __init__(
self,
url: str,
base_url: Optional[str] = None,
max_depth: Optional[int] = 2,
use_async: Optional[bool] = None,
extractor: Optional[Callable[[str], str]] = None,
Expand All @@ -99,6 +100,7 @@ def __init__(

Args:
url: The URL to crawl.
base_url: the base url to check for outside links against.
max_depth: The max depth of the recursive loading.
use_async: Whether to use asynchronous loading.
If True, this function will not be lazy, but it will still work in the
Expand All @@ -123,6 +125,7 @@ def __init__(
"""

self.url = url
self.base_url = base_url if base_url is not None else url
self.max_depth = max_depth if max_depth is not None else 2
self.use_async = use_async if use_async is not None else False
self.extractor = extractor if extractor is not None else lambda x: x
Expand Down Expand Up @@ -187,7 +190,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 +276,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