-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
text() method merges text parts #3457
Comments
OK. This seemt to do the trick: cheerio(elem).html().replaceAll(/<\/?[a-zA-Z0-9=" ]*>/g, ' ').replace(/\s\s+/g, ' ').trim()) But better would if cheerio keep the whitespace which can ve trime manually as user needs to. |
Facing the same issue and hitting it via langchain CheerioWebLoad so I cant use the approach above. |
I believe this is related #2841 and really unfortunate 😬 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
text() method in JQuery keeps whitespaces between text parts. Cheerio unfortunatelly merges text parts from tags thogether givign you quite gibberish words.
See exampel https://api.jquery.com/text/ I tested it by myself and JQuery text() method keeps whitespaces between the text parts of the tags. This is very useful.
Cheerio on the other hand messes text parts alltogther without no spaces which is a pain.
E.g. from this
JQuery text() gives you expected text
PART ONE GENERAL PROVISIONS
but Cheerio gives youPART ONEGENERAL PROVISIONS
Also standard HTML innerText property works the same.
The text was updated successfully, but these errors were encountered: