Relative <base href> produces scheme-less extracted links

Đang mở
#2,550 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@HhH666-ux đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #2552 của @HhH666-ux — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
html, python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
87.2k
Fork
9.1k
Merge trung bình
1 ngày 6 giờ
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của unclecode/crawl4ai

Tất cả issue của unclecode/crawl4ai

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.