Stop parsing a whole page to read its breadcrumb, and work out the shown lists once per render

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 15:52:34 -07:00
1 parent 3bd6da1b19
commit d1e74f3e76
3 files changed
+35 -1

No files matched your search

+7 -1
View File
@@ -186,7 +186,13 @@ class _Crumbs(HTMLParser):
def visible_breadcrumbs(body):
"""[(text, href)] of the breadcrumb a page body shows; the last item has no href."""
parser = _Crumbs()
parser.feed(str(body))
text = str(body)
# The breadcrumb is near the top of a body: feed it in pieces and stop once its nav has
# closed, rather than parsing a whole page of rows.
for i in range(0, len(text), 8192):
parser.feed(text[i:i + 8192])
if parser._done:
break
return parser.items