[Bug]: BestFirstCrawlingStrategy fetches a full batch past max_pages
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 BestFirstCrawlingStrategy 的 _arun_best_first 方法开始,看其中填充每个批次的循环。它计算了 batch_size = min(BATCH_SIZE, remaining),但迭代的是 range(BATCH_SIZE),因此循环应使用 batch_size。使用 max_pages=12 运行复现脚本,确认只抓取 12 个页面。当抓取数量与 max_pages 一致且现有的深度爬取测试仍然通过时即完成。未合并的 PR #2246 使用了相同的模式,请检查它是否存在冲突。
由索引模型根据 Issue 内容生成。
描述
crawl4ai version
0.9.5 (same on 0.9.0)
Expected Behavior
BestFirstCrawlingStrategy with max_pages=N fetches about N pages: the last batch is cut to the remaining budget.
Current Behavior
_arun_best_first computes batch_size = min(BATCH_SIZE, remaining) but pops range(BATCH_SIZE) items, so the last batch is always 10 URLs. They are all fetched, and the results past the limit are dropped. With max_pages=12, 21 pages are fetched for 12 results (24 on 0.9.0).
Is this reproducible?
Yes
Code snippets
import asyncio
from aiohttp import web
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
from crawl4ai.deep_crawling import BestFirstCrawlingStrategy
hits = []
async def handle(request):
hits.append(request.path)
links = "".join(f'<a href="/p{i}">p{i}</a>' for i in range(30)) if request.path == "/" else ""
return web.Response(text=f"<html><body>{links}<p>{'text ' * 200}</p></body></html>", content_type="text/html")
async def main():
app = web.Application()
app.router.add_get("/{tail:.*}", handle)
runner = web.AppRunner(app)
await runner.setup()
await web.TCPSite(runner, "127.0.0.1", 8766).start()
config = CrawlerRunConfig(deep_crawl_strategy=BestFirstCrawlingStrategy(max_depth=1, max_pages=12), stream=True)
async with AsyncWebCrawler() as crawler:
results = [r async for r in await crawler.arun("http://127.0.0.1:8766/", config=config)]
print("results:", len(results), "pages fetched:", len([h for h in hits if h != "/robots.txt"])) # 12 vs 21
await runner.cleanup()
asyncio.run(main())
Suggested fix
for _ in range(batch_size): in the batch-filling loop. The open PR #2246 (configurable batch_size) keeps the same pattern: it computes effective_batch_size but loops over range(self.batch_size).
- 主要语言
- Python
- 星标
- 86.4k
- 派生
- 9k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 21
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
unclecode/crawl4ai 的其他 Issue
-
⚙ Done ✨ Enhancement
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
⚙ Done 🐞 Bug 📌 Root caused
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
[Bug]: PDF images saved with save_images_locally=True come back with an empty src in result.media未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 85/100
unclecode/crawl4ai#2416 · 2 条评论 ·
维护者通常 1 天内回复
-
⚙ Done 🐞 Bug
难度 2/5 1-3 小时 新手友好度 72/100
unclecode/crawl4ai#2382 · 2 条评论 ·
维护者通常 1 天内回复
查看 unclecode/crawl4ai 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/markitdown#2820 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
yt-project/yt#5624 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
NousResearch/hermes-agent#148376 ·
维护者通常 1 天内回复