[BUG] ScrapeElementFromWebsiteTool breaks when only website_url or only css_element is set at init

未关闭
#9,873 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@p-tirth 已经在做这个了。

开始于 2026年11月27日。

  • #9874 来自 @p-tirth —— 未关闭
  • #9890 来自 @Mansi2221 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

The issue names ScrapeElementFromWebsiteTool and SeleniumScrapingTool but no source or test file paths. Start by locating the tool implementation and its tests, then check how initialization selects the argument schema and stores each fixed value. Done means either initialization option can be fixed independently, the remaining argument is requested, and tests cover both cases.

由索引模型根据 Issue 内容生成。

描述

Description

The docs for ScrapeElementFromWebsiteTool describe website_url and css_element as independently optional at initialization: "If provided during initialization, the agent won't need to specify it when using the tool." That only holds when both are given. Fixing just one of them breaks the tool.

  • Only website_url fixed: the tool switches to the empty FixedScrapeElementFromWebsiteToolSchema, so the agent is never asked for css_element and every run raises Both website_url and css_element must be provided.
  • Only css_element fixed: the value is dropped, because it is only stored inside if website_url is not None:. The agent is still asked for a selector.
Steps to Reproduce
from unittest.mock import MagicMock, patch
from crewai_tools import ScrapeElementFromWebsiteTool

MODULE = "crewai_tools.tools.scrape_element_from_website.scrape_element_from_website"
page = MagicMock(content=b"<html><h1>Title</h1><p class='price'>$10</p></html>")

with patch(f"{MODULE}.safe_get", return_value=page):
    a = ScrapeElementFromWebsiteTool(website_url="https://example.com")
    print(list(a.args_schema.model_fields))   # []
    a.run()                                   # ValueError: Both website_url and css_element must be provided.

    b = ScrapeElementFromWebsiteTool(css_element=".price")
    print(b.css_element)                      # None
    print(list(b.args_schema.model_fields))   # ['website_url', 'css_element']
Expected behavior
  • With only website_url fixed, the schema asks the agent for css_element.
  • With only css_element fixed, the selector is kept and the schema asks the agent for website_url.

SeleniumScrapingTool already stores css_element on its own, outside the website_url check.

Environment
  • crewAI and crewAI Tools 1.15.45 (main at 77237ae)
  • Python 3.13, macOS
Possible Solution

Store css_element independently and pick the args schema from what was fixed at init. I have this ready with tests and will open a PR.

Additional context

I used an AI coding assistant while working on this.

主要语言
Python
星标
61.2k
派生
9.2k
平均合并
1 天 14 小时
30 天内合并 PR
180

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

crewAIInc/crewAI 的其他 Issue

查看 crewAIInc/crewAI 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。