Skip to content

fix(crawlers): Decode non-UTF-8 pages correctly in ParselCrawler and BeautifulSoupCrawler - #2260

Merged
vdusek merged 7 commits into
apify:masterfrom
Mantisus:fix-parsel-encoding
Sep 29, 2026
Merged

vdusek merged 7 commits into
apify:masterfrom
Mantisus:fix-parsel-encoding

Conversation

@Mantisus

Copy link
Copy Markdown
Collaborator

Description

ParselParser decoded every response as UTF-8, so pages in other encodings came out garbled in ParselCrawler, AdaptivePlaywrightCrawler and PydanticAiCrawler. BeautifulSoupParser ignored the Content-Type charset and returned an empty soup for a page with a <meta> charset and a single invalid byte.

Both parsers now decode the page with the encoding it declares: the BOM, then the Content-Type charset, then an XML declaration or <meta> tag. Labels are resolved per the WHATWG Encoding Standard, as browsers do, so e.g. ISO-8859-1 is read as windows-1252, and unknown labels are ignored.

If the page declares no encoding, each parser falls back to its default behaviour: BeautifulSoupParser detects the encoding itself and ParselParser reads the page as UTF-8.

Testing

  • Added new unit tests

✍️ Drafted by Claude Code

@Mantisus Mantisus self-assigned this Sep 28, 2026
@vdusek vdusek changed the title fix(crawlers): Decode pages with their declared encoding in ParselParser and BeautifulSoupParser fix(crawlers): Decode non-UTF-8 pages correctly in ParselCrawler and BeautifulSoupCrawler Sep 29, 2026

@vdusek vdusek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! I just pushed a few minor follow-up commits.

Comment thread src/crawlee/_utils/html.py Outdated
@vdusek
vdusek merged commit 209e8a1 into apify:master Sep 29, 2026
34 checks passed
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.

4 participants