mirror of
https://github.com/SillyTavern/Extension-WebSearch.git
synced 2026-10-15 13:31:52 +00:00
[GH-ISSUE #9] [Feature] Regex for website scraping #4
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
SillyTavern/Extension-WebSearch#4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @NXTler on GitHub (Feb 20, 2025).
Original GitHub issue: https://github.com/SillyTavern/Extension-WebSearch/issues/9
Greetings,
I recently started experimenting with this extension and found that there are a lot of characters wasted due to website formatting, like multiple newlines for no apparent reason. I propose the integration of the regex system into the scraping process, so that we can have more information to process (due to increased information density) and better formatting (like removing the extra space before a new paragraph, like some websites have).
@NXTler commented on GitHub (Mar 3, 2025):
In case someone is searching for a quick and dirty solution - you can replace at
const textline 708 in index.js with something likeThis cleans up the output a bit, but I'm unsure if you actually get more information with this.
@Cohee1207 commented on GitHub (Mar 3, 2025):
There's already a method that post-processes text in core code. So if you need specific processing, add it there.
github.com/SillyTavern/SillyTavern@938c8a9a36/public/scripts/utils.js (L1515)@NXTler commented on GitHub (Mar 3, 2025):
Thanks, I will experiment a bit and try to get more info into the budget with this. When I have something working I might commit it.
@Cohee1207 commented on GitHub (Mar 3, 2025):
These look good generally.
This is questionable. I think if you're scraping articles about emojis, losing emojis would be detrimental.
@NXTler commented on GitHub (Mar 3, 2025):
For the last one I just search how to remove emojis in js and haven't spend much time testing it, I'm also unsure if that's the correct way.
@NXTler commented on GitHub (Mar 3, 2025):
Okay, this is how it looks now:
This really cleans up the output without changing the actual information that much. Emojis are still a bit weird, as they sometimes have or not have leading/trailing spaces.
EDIT: fixed some issues with the replacements, should work in more cases now while preserving more information.
EDIT: Further improved leading space detection
@NXTler commented on GitHub (Mar 3, 2025):
Seems to work correctly with the character budget.
@NXTler commented on GitHub (Mar 13, 2025):
Okay, after some edits, I would call these expressions good. They differ quite a lot from the ones in
postProcessText, so how should go about adding these? Or should I rather create a new function for this?@Cohee1207 commented on GitHub (Mar 13, 2025):
I'm not sure about a new function, especially around removing emojis. The rest of the regex look fine.
@NXTler commented on GitHub (Mar 13, 2025):
It doesn't remove emojis completely, it simply collapses multiple into one to handle unnecessary spamming from some websites.
@Cohee1207 commented on GitHub (Mar 13, 2025):
You mean if the same emoji is repeated multiple times? You can also target the emoji with a unicode group instead. This example will match all emojis in a string:
/(\p{Emoji_Presentation}|\p{Extended_Pictographic})/gu@NXTler commented on GitHub (Mar 13, 2025):
Yes, that's what I meant. If one emoji is repeated multiple times, it will be reduced to only one instance.
I wasn't aware of that functionality. In that case, the regex would look like this:
.replace(/(\p{Emoji_Presentation}|\p{Extended_Pictographic})(?=\1)/gu, '') // Remove spammed emojisSo, how should I add these to
postProcessText? I have some different approaches for some Regexs (see removing double spaces and leading and trailing spaces) to retain more information.@NXTler commented on GitHub (Mar 16, 2025):
@Cohee1207 I'm sorry for the ping, as I can see that you are very busy and probably have better more important problems. However, I have some time to spend and would like to complete my issue based on you suggestions.
@Cohee1207 commented on GitHub (Mar 16, 2025):
These should go to postProcessText.