Conversation
… html_bytes in extract() Co-authored-by: rahulbot <673178+rahulbot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve content decoding and encoding in webpages.fetch
Return raw bytes from Aug 26, 2026
webpages.fetch; decode HTML once in extract()
rahulbot
requested changes
Aug 26, 2026
rahulbot
left a comment
Contributor
There was a problem hiding this comment.
Rebase this off of the fix-more-unit-tests branch, which should help the unit tests pass.
…sts-mock, update all tests Co-authored-by: rahulbot <673178+rahulbot@users.noreply.github.com>
Author
Done — rebased onto |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
webpages.fetchwas returningresponse.text, causing requests to auto-decode bytes→str, only for downstream code (e.g.languages._from_text) to re-encode str→bytes before passing to libraries that expect bytes. This redundant round-trip risks encoding errors and wastes CPU.Changes
webpages.fetch()now returnsresponse.content(bytes) instead ofresponse.text(str)webpages.html_from_bytes()decodes raw bytes →stronce usingtrafilatura.utils.decode_file, which correctly handles charset declarations embedded in the HTMLextract()accepts a new optionalhtml_bytes: bytesparameter; bytes (from fetch or caller) are decoded once viahtml_from_bytes()before all downstream processinglanguages._from_text()no longer redundantly callstrafilatura.utils.decode_fileon an already-decodedstrUsage
Callers that fetch HTML themselves can now pass raw bytes directly:
The existing
html_text: strparameter remains fully supported for backward compatibility.