Quote:
Originally Posted by moldy
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)