Skip to content

Don't stop scrolling on the first round that adds no results - #21

Open
Benjapieres wants to merge 1 commit into
zohaibbashir:mainfrom
Benjapieres:fix/scroll-lazy-load
Open

Don't stop scrolling on the first round that adds no results#21
Benjapieres wants to merge 1 commit into
zohaibbashir:mainfrom
Benjapieres:fix/scroll-lazy-load

Conversation

@Benjapieres

Copy link
Copy Markdown

Fixes #15.

Problem

The scroll loop breaks as soon as one round finds the same count as the previous one:

if found == previously_counted:
    logging.info("Arrived at all available")
    break

Google lazy-loads the results panel, so a flat round normally means the next batch is still in flight — not that the list ended. The loop spins faster than results arrive and exits almost immediately, which is what #15 reports.

Measurement

Scroll phase only (no extraction), same query, unreachable target so both run to exhaustion:

query current main with this patch
"cafeterias en Buenos Aires" 22 results, 5 rounds, 0.6s 54 results, 16 rounds, 8.6s
"restaurantes en Cordoba Argentina" 18 results, 3 rounds, 0.4s 72 results, 20 rounds, 9.2s

Current main gives up in under a second — before the first lazy batch has even landed. Asking for -t 50 silently gets you 22.

Fix

Only conclude the list is exhausted after MAX_STAGNANT_SCROLLS consecutive flat rounds, waiting SCROLL_SETTLE_MS between them.

The wait is paid only when the count looks stagnant. Runs that keep finding results never hit it, so the hot path stays exactly as fast as today and the wait-for-element approach from #2 is preserved — no blind sleep was added to the loop. Worst case cost when the list really is exhausted is ~3s.

Verification

End to end with -t 50:

INFO - Currently Found: 22
INFO - Currently Found: 28
INFO - Currently Found: 40
INFO - Currently Found: 43
INFO - Currently Found: 49
INFO - Currently Found: 55
INFO - Total Found: 50
INFO - Saved 49 places to result.csv (append=False)

49 places scraped (one listing had no name and was skipped by the existing guard), 33 with phone numbers, 35 with websites. On main this same command stops at the first 22.

Independent of #19 and #20 — different function, no overlap.

🤖 Generated with Claude Code

Fixes zohaibbashir#15.

The scroll loop breaks as soon as one round finds the same count as the
previous one. Google lazy-loads the results panel, so a flat round
normally means the next batch is still in flight, not that the list
ended. The loop spins faster than results arrive and exits almost
immediately.

Measured on current main, scrolling until exhaustion with an
unreachable target:

    query                                current   tolerant
    "cafeterias en Buenos Aires"           22        54
    "restaurantes en Cordoba Argentina"    18        72

Current main gives up after 3-5 rounds in under a second, before the
first lazy batch has even landed.

Only conclude the list is exhausted after MAX_STAGNANT_SCROLLS
consecutive flat rounds, waiting SCROLL_SETTLE_MS between them. The
wait is paid only when the count looks stagnant, so runs that keep
finding results stay as fast as they are today and the wait-for-element
approach from zohaibbashir#2 is preserved on the hot path.

Verified end to end with -t 50: the count climbs 22 -> 28 -> 40 -> 43
-> 49 -> 55 and 49 places are scraped, where main would have stopped
at the first 22.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Insufficient Scrolling for Infinite Load

1 participant