View Single Post
Old 03-19-2024, 12:57 PM   #18
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by moldy View Post
However when experimenting with my actual working file I found the massive size of the data in the find field somewhat unwieldy to say the least.
You were who asked to put all the searched words in the find field :-).
With your new search string, you could use your json file in this way, avoiding the need of hundred of ptyhon replaces :
Code:
# your code : 
    # return match.group().replace('John','Mick').replace('George','Keith').replace('Paul','Ronnie').replace('Ringo','Charlie')

# Alternative code :
    # insert here the code to load the json file into the dict "equiv"
    m = match.group(0) 
    for key in equiv:
        m = m.replace(key, equiv[key])
    return m
With this code, the function is generic, you need to modify only the json file for another set of searched words.

If you're sure that none of the searched words is inside a tag (as "body", "span", or a class name, for example), you could even search the whole html page, much quicker :
find : <body[^>]*>\K(.+)</body> (with "dot all" checked)

Last edited by lomkiri; 03-19-2024 at 05:19 PM.
lomkiri is offline   Reply With Quote