[Bug]: PDF images saved with save_images_locally=True come back with an empty src in result.media

Đang mở Phù hợp với người mới
#2,469 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 2 ngày

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

Từ ngày 4/11/2026.

  • #2497 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
78/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ệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại bộ xử lý PDF ở PDFContentScrapingStrategy.scrap() và kiểm tra cách các từ điển hình ảnh đã lưu được truyền vào ScrapingResult(media={"images": [...]}); sau đó xem schema MediaItem để biết những trường nào được giữ lại. Tái hiện lỗi bằng ví dụ PDF Pillow trong issue. Hoàn tất khi mỗi hình ảnh đã lưu trong result.media.images có cách để xác định vị trí tệp của nó trong image_save_dir, đồng thời hành vi hình ảnh nội tuyến vẫn được giữ nguyên.

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

Mô tả

🐞 Bug 🩺 Needs Triage
crawl4ai version

0.9.5 (develop at 78405d6)

Expected Behavior

With PDFContentScrapingStrategy(extract_images=True, save_images_locally=True), each entry in result.media.images should point at the image file that was written to image_save_dir.

Current Behavior

The image is written to disk, but the MediaItem in result.media.images has src == "" and data == "", so there is no way to find the file from the result.

The PDF processor reports a saved image as {"path": ..., "format": ..., "width": ..., ...}. scrap() passes these dicts straight into ScrapingResult(media={"images": [...]}), and MediaItem has no path field, so pydantic drops it. Same kind of schema mismatch as #2374 for links. Inline images (save_images_locally=False) are fine because data is a MediaItem field.

Is this reproducible?

Yes

Inputs Causing the Bug
Any PDF with an embedded image, e.g. one made by Pillow (below).
Steps to Reproduce
1. Make a one-page PDF containing an image.
2. Scrape it with PDFContentScrapingStrategy(extract_images=True, save_images_locally=True, image_save_dir=...).
3. Look at result.media.images.
Code snippets
import os, tempfile
from PIL import Image
from crawl4ai.processors.pdf import PDFContentScrapingStrategy

d = tempfile.mkdtemp()
pdf = os.path.join(d, "doc.pdf")
Image.new("RGB", (40, 30), "red").save(pdf)

strategy = PDFContentScrapingStrategy(
    extract_images=True, save_images_locally=True, image_save_dir=os.path.join(d, "imgs")
)
result = strategy.scrap(pdf, "")
print(os.listdir(os.path.join(d, "imgs")))
print(result.media.images[0].model_dump())

Output:

['page_1_img_1.jpg']
{'src': '', 'data': '', 'alt': '', 'desc': '', 'score': 0, 'type': 'image', 'group_id': 0, 'format': 'jpeg', 'width': 40}
OS

Linux

Python version

3.12

Browser

N/A (PDF scraping strategy called directly)

Browser version

N/A

Error logs & Screenshots (if applicable)

No error; success is True.

Ngôn ngữ chính
Python
Star
86.8k
Fork
9k
Merge trung bình
2 ngày 3 giờ
Pull request đã merge (30 ngày)
26

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.