Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Bug]: BestFirstCrawlingStrategy fetches a full batch past max_pages

オープン 初心者向け
#2,381 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@rtmalikian がすでに取り組んでいます。

2026年10月15日 から。

  • #2383 @rtmalikian による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

BestFirstCrawlingStrategy の _arun_best_first メソッドのうち、各バッチを埋めるループから始めてください。このループでは batch_size = min(BATCH_SIZE, remaining) を計算していますが、反復には range(BATCH_SIZE) を使っているため、ループは batch_size を使うべきです。max_pages=12 で再現スクリプトを実行し、取得されるページが 12 件だけであることを確認してください。取得数が max_pages と一致し、既存の deep-crawl テストがすべて通れば完了です。オープン中の 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
スター
85.4k
フォーク
8.9k
平均マージ
5日 7時間
マージ済み PR(30日)
23

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

unclecode/crawl4ai のほかの issue

unclecode/crawl4ai の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。