[Bug]: PDF URI links are silently discarded by PDFContentScrapingStrategy due to Links schema mismatch
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in crawl4ai/processors/pdf/__init__.py at PDFContentScrapingStrategy.scrap(), where the {"urls": []} dictionary is built, then compare it with Links, Link and ScrapingResult in crawl4ai/models.py. Reproduce with the snippet in the issue, which should show URI links present in processor.py output but missing from scraped.links. The maintainer has not yet confirmed the link representation, so agree on the contract before changing it. Done means a generated PDF's URI link appears in ScrapingResult.links with its page preserved.
由索引模型根据 Issue 内容生成。
描述
crawl4ai version
0.9.5 (also observed in 0.9.4).
Expected Behavior
URI link annotations extracted from a PDF should survive PDFContentScrapingStrategy.scrap() and be accessible in the returned ScrapingResult.links, with their source page numbers preserved or represented by an explicitly documented contract.
This report concerns preservation of the extracted link inventory, not reconstructing clickable text positions in HTML/Markdown or PDF-internal page destinations.
Current Behavior
The public processor extracts the URI correctly, but the public PDF scraping strategy returns success=True and empty internal / external link lists for the same file.
The apparent cause is a schema mismatch:
PDFContentScrapingStrategy.scrap()buildslinks = {"urls": []}and appends{"url": link, "page": page.page_number}.- It passes that dictionary to
ScrapingResult. ScrapingResult.linksis typed asLinks, which defines onlyinternalandexternal. ItsLinkitems usehrefrather thanurland have no explicit PDF page field.- The unrecognized
urlskey is silently ignored during model construction, losing the collected links.
Sources: PDF scraper, models, and PDF processor.
The PDF parsing documentation also describes links["urls"], suggesting that preserving PDF links is intended, but the current result model cannot represent that structure.
Is this reproducible?
Yes.
Inputs Causing the Bug
A local, generated one-page PDF containing one URI annotation. No browser, network requests, external files, credentials, or application-specific adapter is needed. The page is intentionally blank apart from its annotation to isolate link preservation.
Steps to Reproduce
- Use Python 3.12 and install
pip install "crawl4ai[pdf]==0.9.5". - Save the following snippet as
repro_pdf_links.py. - Run
python repro_pdf_links.py. - Observe that the processor contains the URI but the scraping result has empty link lists.
Code snippets
from pathlib import Path
from tempfile import TemporaryDirectory
from pypdf import PdfWriter
from pypdf.annotations import Link
from crawl4ai.processors.pdf import PDFContentScrapingStrategy
from crawl4ai.processors.pdf.processor import NaivePDFProcessorStrategy
with TemporaryDirectory() as folder:
path = Path(folder) / "linked.pdf"
writer = PdfWriter()
writer.add_blank_page(width=612, height=792)
writer.add_annotation(
0,
Link(rect=(20, 20, 200, 40), url="https://example.org/reference"),
)
writer.write(path)
processed = NaivePDFProcessorStrategy(extract_images=False).process(path)
scraped = PDFContentScrapingStrategy(extract_images=False).scrap(str(path), "")
print("processor links:", processed.pages[0].links)
print("scraping success:", scraped.success)
print("scraping links:", scraped.links.model_dump())
OS
macOS 27.0.1, Apple Silicon (arm64).
Python version
3.12.13; pypdf 6.20.1.
Browser
Not applicable; the reproduction uses a local PDF and public SDK methods directly.
Browser version
Not applicable.
Error logs & Screenshots (if applicable)
No exception is raised. Actual output on 0.9.5:
processor links: ['https://example.org/reference']
scraping success: True
scraping links: {'internal': [], 'external': []}
Proposed direction / contribution
I would like to contribute a focused fix targeting develop, with regression coverage using a generated PDF and updated documentation. Before changing the public link contract, could you confirm the intended representation?
One possible approach is to map PDF URI links into the existing internal / external structure using href, and add an optional 1-based page field to Link so PDF page attribution is not lost. For remote PDFs, classification could reuse the existing URL classification rules; for local PDFs without a source URL, treating URI links as external is a possible fallback, subject to maintainer preference.
This is a proposal rather than an assumed API decision. Reader reuse / parallel parsing optimization and reconstruction of inline clickable text would remain outside this fix.
- 主要语言
- Python
- 星标
- 85.9k
- 派生
- 8.9k
- 平均合并
- 4 天 20 分钟
- 30 天内合并 PR
- 19
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
unclecode/crawl4ai 的其他 Issue
-
[Bug]: Text after an inline <link>, <meta>, <style> or <noscript> is dropped from cleaned_html and markdown可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 85/100
unclecode/crawl4ai#2416 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug]: Since 0.9.1, Linux launches chrome-headless-shell instead of Chromium可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 72/100
unclecode/crawl4ai#2382 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug]: BestFirstCrawlingStrategy fetches a full batch past max_pages可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 74/100
unclecode/crawl4ai#2381 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug]: CrawlerRunConfig.clone() drops fallback_fetch_function, so deep crawls never use it可能已有人在做 @siva23367 于 6 天前认领。 未关闭🐞 Bug 🩺 Needs Triage
难度 2/5 1-3 小时 新手友好度 78/100
unclecode/crawl4ai#2379 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug]: Docker memory guard reads host RAM when no container limit is set — cgroup v2 "max" defeats get_container_memory_percent可能已有人在做 @Battleplus 于 63 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
unclecode/crawl4ai#2123 · 1 条评论 ·
维护者通常 2 天内回复
查看 unclecode/crawl4ai 的全部 Issue
相似的 Issue
-
README.zh-CN/ja/es still hard-code 501 test counts after README.md went count-free可能已有人在做 @Aaqibhafeezkhan 今天认领。 未关闭beginner documentation good first issue
难度 2/5 1-3 小时 新手友好度 75/100
BistaDinesh03/critique#164 · 1 条评论 ·
维护者通常 1 天内回复
-
bug IO
难度 2/5 1-3 小时 新手友好度 65/100
MrNeRF/LichtFeld-Studio#3824 ·
维护者通常 1 天内回复
-
bug confirmed issue
难度 2/5 1-3 小时 新手友好度 72/100
open-webui/open-webui#33200 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
-
The changelog workflow excludes otelbot but not dependabot, so every Dependabot pull request fails the changelog check可能已有人在做 @ocelotl 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 82/100
open-telemetry/opentelemetry-python#5825 ·
维护者通常 2 天内回复