Skip to content

fix: skip anti-bot detection for PDF responses - #2137

Open
nightcityblade wants to merge 1 commit into
unclecode:developfrom
nightcityblade:fix/issue-2135
Open

fix: skip anti-bot detection for PDF responses#2137
nightcityblade wants to merge 1 commit into
unclecode:developfrom
nightcityblade:fix/issue-2135

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Summary

Fixes #2135.

Treat responses declared as application/pdf like other binary content before anti-bot classification. This prevents PDFCrawlerStrategy's intentional 33-byte HTML placeholder from triggering retries, fallback fetching, and the final failure veto after PDF extraction succeeds.

List of files changed and why

  • crawl4ai/async_webcrawler.py - detect PDF response content types and bypass HTML-specific anti-bot checks in both classification stages.
  • tests/test_issue_2135_pdf_antibot.py - exercise the real PDFCrawlerStrategy through AsyncWebCrawler.arun() and verify one attempt, success, and no fallback.

How Has This Been Tested?

  • .venv/bin/python -m pytest tests/test_issue_2135_pdf_antibot.py -q - 1 passed.
  • .venv/bin/python tests/proxy/test_antibot_detector.py - 47 passed, 0 failed.
  • .venv/bin/ruff check --isolated --select E9,F63,F7,F82 --ignore F821 crawl4ai/async_webcrawler.py tests/test_issue_2135_pdf_antibot.py - passed.
  • .venv/bin/black --check --target-version py312 --fast tests/test_issue_2135_pdf_antibot.py - passed.
  • .venv/bin/python -m compileall -q crawl4ai/async_webcrawler.py tests/test_issue_2135_pdf_antibot.py - passed.
  • git diff --check upstream/develop...HEAD - passed.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas - N/A; the PDF-response condition is explicit and covered by a focused regression test.
  • I have made corresponding changes to the documentation - N/A; this fixes the implementation to match the existing PDF parsing documentation.
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing relevant tests pass locally with my changes

@nightcityblade

Copy link
Copy Markdown
Contributor Author

CI note: the only failing check is the repository's notify-discord job because DISCORD_WEBHOOK is empty for this fork PR. The job exits before any code validation; the focused PDF/anti-bot tests and lint checks reported in the PR body are green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant