fixrecursivewget/urlencode.py
2015-03-28 10:43:05 +01:00

23 lines
482 B
Python
Executable file

#!/usr/bin/env python3
import re
import sys
for filename in sys.argv[1:]:
try:
with open(filename) as f:
data = f.read()
except UnicodeDecodeError:
continue
def aux(match):
s = match.group(0)
s = s.replace("?", "%3F")
s = s.replace("&", "%26")
return s
data = re.sub(r'href="[^"]+"', aux, data)
data = re.sub(r'src="[^"]+"', aux, data)
with open(filename, "w") as f:
f.write(data)