Relative <base href> produces scheme-less extracted links

Offen
#2,550 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@HhH666-ux arbeitet bereits daran.

Seit 13.11.2026.

  • #2552 von @HhH666-ux — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
html, python
Bereich
backend

Rechercherichtung

The relevant code is LXMLWebScrapingStrategy._process_element() in the content scraping strategy module, which reads <base href> and uses it as url without resolving it, plus the normalize_url helper it should match. Reproduce with the snippet in the issue to confirm the scheme-less /sub/page.html output. Done means relative and absolute <base href> values both yield absolute internal links. Pull request #2552 is already open against this issue, so check with the maintainers before starting.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Description

LXMLWebScrapingStrategy._process_element() reads <base href> and assigns it to url as-is. When the page declares a relative base (e.g. <base href="/sub/">), every relative link is resolved against that relative string, so the extracted links come out scheme- and host-less (/sub/page.html) even though the same document without a <base> element yields an absolute link.

Reproduction
import sys
from lxml import html as lhtml
from crawl4ai.content_scraping_strategy import LXMLWebScrapingStrategy

strategy = LXMLWebScrapingStrategy()
html = "<html><head><base href='/sub/'></head><body><a href='page.html'>Page</a></body></html>"
result = strategy.process_element("https://example.com/app/index.html", lhtml.fromstring(html))
print(list(result["internal_links_dict"]))
  • Actual: ['/sub/page.html']
  • Expected: ['https://example.com/sub/page.html']

Absolute <base href="https://cdn.example.com/docs/"> behaves as before.

Expected fix

Resolve the declared base against the page URL with urljoin(url, base_href) before it is used, so relative and absolute <base> values both produce absolute links. This is the same resolution normalize_url already performs when no <base> is present.

I will open a small PR with a regression test covering root-relative, document-relative, absolute and missing <base> values.

Vorherrschende Sprache
Python
Sterne
87.2k
Forks
9.1k
Ø Merge
1 T. 6 Std.
Gemergte PRs (30 T.)
25

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus unclecode/crawl4ai

Alle Issues in unclecode/crawl4ai

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.