Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug]: BestFirstCrawlingStrategy fetches a full batch past max_pages

Aperta Adatta ai principianti
#2,381 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@rtmalikian ci sta già lavorando.

Dal 15/10/2026.

  • #2383 di @rtmalikian — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Inizia dal metodo _arun_best_first di BestFirstCrawlingStrategy, nel ciclo che riempie ogni batch. Calcola batch_size = min(BATCH_SIZE, remaining) ma itera su range(BATCH_SIZE), quindi il ciclo dovrebbe usare batch_size. Esegui lo script di riproduzione con max_pages=12 e conferma che vengono recuperate solo 12 pagine. È completato quando il numero di recuperi corrisponde a max_pages e i test deep-crawl esistenti continuano a passare. La PR aperta #2246 usa lo stesso schema, quindi controllala per eventuali conflitti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
Python
Stelle
85.4k
Fork
8.9k
Merge medio
5g 7h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di unclecode/crawl4ai

Tutte le issue di unclecode/crawl4ai

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.