Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crawl4ai/async_url_seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ def _parse_head(src: str) -> Dict[str, Any]:
except json.JSONDecodeError:
pass
# Extract html lang attribute
html_elem = doc.find(".//html")
# ``fromstring`` returns the document's ``<html>`` element for a
# complete HTML document. ``.//html`` only searches descendants, so
# it misses that root element and drops its language declaration.
html_elem = doc if doc.tag.lower() == "html" else doc.find(".//html")
if html_elem is not None:
info["lang"] = html_elem.attrib.get("lang", "")
return info
Expand Down
2 changes: 0 additions & 2 deletions crawl4ai/content_scraping_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def fetch_image_file_size(img, base_url):
return None
except InvalidSchema:
return None
finally:
return


class ContentScrapingStrategy(ABC):
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_content_scraping_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from unittest.mock import Mock, patch

from crawl4ai.content_scraping_strategy import fetch_image_file_size


def test_fetch_image_file_size_returns_content_length():
image = {"src": "/image.png"}
response = Mock(status_code=200, headers={"Content-Length": "1024"})

with patch("crawl4ai.content_scraping_strategy.requests.head", return_value=response):
assert fetch_image_file_size(image, "https://example.com/page") == "1024"
10 changes: 9 additions & 1 deletion tests/unit/test_sitemap_namespace_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ def get_scores(self, tokens):

sys.modules.setdefault("rank_bm25", SimpleNamespace(BM25Okapi=_FakeBM25))

from crawl4ai.async_url_seeder import AsyncUrlSeeder
from crawl4ai.async_url_seeder import AsyncUrlSeeder, _parse_head


def test_parse_head_reads_language_from_document_root():
info = _parse_head(
'<html lang="tr"><head><title>Başlık</title></head><body></body></html>'
)

assert info["lang"] == "tr"


class DummyResponse:
Expand Down