langchain_community.document_loaders.news.NewsURLLoader

class langchain_community.document_loaders.news.NewsURLLoader(urls: List[str], text_mode: bool = True, nlp: bool = False, continue_on_failure: bool = True, show_progress_bar: bool = False, **newspaper_kwargs: Any)[source]

从URL使用`Unstructured`加载新闻文章。

Parameters
  • urls (List[str]) – 要加载的URL。每个URL都加载到自己的文档中。

  • text_mode (bool) – 如果为True,则从URL提取文本并将其用作页面内容。否则,提取原始HTML。

  • nlp (bool) – 如果为True,则对提取的内容执行自然语言处理(NLP),如提供摘要和提取关键词。

  • continue_on_failure (bool) – 如果为True,则即使对特定URL加载失败,也继续加载文档。

  • show_progress_bar (bool) – 如果为True,则使用tqdm显示加载进度条。需要安装tqdm,pip install tqdm

  • **newspaper_kwargs – 要传递给 newspaper.Article() 的任何其他命名参数。

  • newspaper_kwargs (Any) –

Return type

None

Example

from langchain_community.document_loaders import NewsURLLoader

loader = NewsURLLoader(
    urls=["<url-1>", "<url-2>"],
)
docs = loader.load()
Newspaper 参考文档:

https://newspaper.readthedocs.io/en/latest/

使用文件路径进行初始化。

Methods

__init__(urls[, text_mode, nlp, ...])

使用文件路径进行初始化。

alazy_load()

一个用于文档的惰性加载器。

aload()

将数据加载到文档对象中。

lazy_load()

一个用于文档的惰性加载器。

load()

将数据加载到文档对象中。

load_and_split([text_splitter])

加载文档并分割成块。块作为文档返回。

__init__(urls: List[str], text_mode: bool = True, nlp: bool = False, continue_on_failure: bool = True, show_progress_bar: bool = False, **newspaper_kwargs: Any) None[source]

使用文件路径进行初始化。

Parameters
  • urls (List[str]) –

  • text_mode (bool) –

  • nlp (bool) –

  • continue_on_failure (bool) –

  • show_progress_bar (bool) –

  • newspaper_kwargs (Any) –

Return type

None

async alazy_load() AsyncIterator[Document]

一个用于文档的惰性加载器。

Return type

AsyncIterator[Document]

async aload() List[Document]

将数据加载到文档对象中。

Return type

List[Document]

lazy_load() Iterator[Document][source]

一个用于文档的惰性加载器。

Return type

Iterator[Document]

load() List[Document][source]

将数据加载到文档对象中。

Return type

List[Document]

load_and_split(text_splitter: Optional[TextSplitter] = None) List[Document]

加载文档并分割成块。块作为文档返回。

不要覆盖此方法。应该被视为已弃用!

参数:
text_splitter: 用于分割文档的TextSplitter实例。

默认为RecursiveCharacterTextSplitter。

返回:

文档列表。

Parameters

text_splitter (Optional[TextSplitter]) –

Return type

List[Document]

Examples using NewsURLLoader