跳到主要内容
Mastodon 是一个联邦式社交媒体和社交网络服务。
这个加载器使用 Mastodon.py Python 包,从一个 Mastodon 账户列表中抓取“toots”的文本。 默认情况下,无需任何身份验证即可查询公共账户。如果查询非公共账户或实例,您必须为您的账户注册一个应用程序以获取访问令牌,并设置该令牌和您的账户的 API 基础 URL。 然后您需要以 @账户@实例 的格式传入您要提取的 Mastodon 账户名称。
from langchain_community.document_loaders import MastodonTootsLoader
pip install -qU  Mastodon.py
loader = MastodonTootsLoader(
    mastodon_accounts=["@Gargron@mastodon.social"],
    number_toots=50,  # Default value is 100
)

# Or set up access information to use a Mastodon app.
# Note that the access token can either be passed into
# constructor or you can set the environment "MASTODON_ACCESS_TOKEN".
# loader = MastodonTootsLoader(
#     access_token="<ACCESS TOKEN OF MASTODON APP>",
#     api_base_url="<API BASE URL OF MASTODON APP INSTANCE>",
#     mastodon_accounts=["@Gargron@mastodon.social"],
#     number_toots=50,  # Default value is 100
# )
documents = loader.load()
for doc in documents[:3]:
    print(doc.page_content)
    print("=" * 80)
<p>It is tough to leave this behind and go back to reality. And some people live here! I’m sure there are downsides but it sounds pretty good to me right now.</p>
================================================================================
<p>I wish we could stay here a little longer, but it is time to go home 🥲</p>
================================================================================
<p>Last day of the honeymoon. And it’s <a href="https://mastodon.social/tags/caturday" class="mention hashtag" rel="tag">#<span>caturday</span></a>! This cute tabby came to the restaurant to beg for food and got some chicken.</p>
================================================================================
toot 文本(文档的 page_content)默认是 Mastodon API 返回的 HTML。
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.