[Bug]: robots.txt rules ending in `$` never match on Python 3.13 and older
Maintainer thường phản hồi trong vòng 1 ngày
Đá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
- 30/100
Hướng nghiên cứu
Start with patched_applies_to in crawl4ai/utils.py, where the robots.txt rule path is checked for a trailing $ or %24, and with the RobotsParser code that calls it. Run the reproduction script on Python 3.13 to confirm the four can_fetch results. Done means *.pdf$ blocks report.pdf, Allow: /$ allows the home page, and the tests cover both cases. The author says they are opening a PR for this, so check for one before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
crawl4ai version
0.9.5 (also reproduced on develop at 1a6eddb)
Expected Behavior
A robots.txt rule that ends in $ only matches URLs that end at that point (RFC 9309, section 2.2.3). With check_robots_txt=True, Disallow: /*.pdf$ keeps the crawler away from /files/report.pdf, and Allow: /$ lets it fetch the home page.
Current Behavior
On Python 3.13 and older, rules ending in $ never match:
Disallow: /*.pdf$does not block/files/report.pdf, so the crawler fetches URLs the site disallows.- With
Allow: /$followed byDisallow: /, the home page is disallowed as well.
Below 3.14, urllib.robotparser.RuleLine quotes the rule path, so the $ is already %24 when patched_applies_to in crawl4ai/utils.py sees it. Its pattern.endswith('\\$') check never fires, and the regex looks for a literal %24. Rules without * (like Allow: /$) don't reach that code and are compared with startswith('/%24').
Python 3.14 supports $ natively and isn't affected. The description of #2278 mentions this gap ("Happy to do it separately"); I couldn't find an issue or PR for it.
Is this reproducible?
Yes
Inputs Causing the Bug
User-agent: *
Disallow: /*.pdf$
and
User-agent: *
Allow: /$
Disallow: /
Steps to Reproduce
Run the script below with Python 3.13. It serves the two robots.txt files from local HTTP servers, so no network is needed.
Code snippets
import asyncio
import tempfile
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
from crawl4ai.utils import RobotsParser
ROBOTS = {
8765: b"User-agent: *\nDisallow: /*.pdf$\n",
8766: b"User-agent: *\nAllow: /$\nDisallow: /\n",
}
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.end_headers()
self.wfile.write(ROBOTS[self.server.server_port])
def log_message(self, *args):
pass
for port in ROBOTS:
server = HTTPServer(("127.0.0.1", port), Handler)
threading.Thread(target=server.serve_forever, daemon=True).start()
async def main():
parser = RobotsParser(cache_dir=tempfile.mkdtemp())
for url in [
"http://127.0.0.1:8765/files/report.pdf",
"http://127.0.0.1:8765/files/report.pdf.html",
"http://127.0.0.1:8766/",
"http://127.0.0.1:8766/page",
]:
print(url, "->", await parser.can_fetch(url, "bot"))
asyncio.run(main())
Output:
http://127.0.0.1:8765/files/report.pdf -> True
http://127.0.0.1:8765/files/report.pdf.html -> True
http://127.0.0.1:8766/ -> False
http://127.0.0.1:8766/page -> False
Expected:
http://127.0.0.1:8765/files/report.pdf -> False
http://127.0.0.1:8765/files/report.pdf.html -> True
http://127.0.0.1:8766/ -> True
http://127.0.0.1:8766/page -> False
OS
Windows 11
Python version
3.13.5 (3.11 and 3.12 quote the rule path the same way)
Browser
Not used (RobotsParser only fetches robots.txt with aiohttp)
Browser version
Error logs & Screenshots (if applicable)
No error; can_fetch() returns the wrong answer.
I'm opening a PR that treats a trailing %24 as the end anchor in patched_applies_to, with tests.
AI-assisted: found and reproduced with an AI coding agent; the example above was run locally.
- 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
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của unclecode/crawl4ai
-
BUG: UserAgentGenerator.generate ignores browser_type and returns a random browser stackCó thể đã có người làm @HhH666-ux đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Hardened docker-compose (read_only) keeps full Chromium from starting: crashpad needs a writable ~/.configCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở🐞 Bug 📌 Root caused
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
unclecode/crawl4ai#2494 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature]: Crawl4aiDockerClient has no public option for the API token the 0.9 server requiresĐang mở⚙ Done ✨ Enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
⚙ Done 🐞 Bug 📌 Root caused
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: PDF images saved with save_images_locally=True come back with an empty src in result.mediaĐang mở⚙ Done 🐞 Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
unclecode/crawl4ai#2469 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của unclecode/crawl4ai
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
521xueweihan/HelloGitHub#4385 ·
-
🐛 bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
pdm-project/pdm#4012 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
pollen-robotics/reachy_mini_conversation_app#611 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 91/100
aws-samples/sample-per-model-bedrock#913 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
lesson-submission pending-review
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Ikalus1988/MisakaNet#5115 ·
Maintainer thường phản hồi trong vòng 1 ngày