-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_utf16.py
More file actions
27 lines (23 loc) · 1001 Bytes
/
replace_utf16.py
File metadata and controls
27 lines (23 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys
try:
with open('studyverse (1).html', 'rb') as f:
content = f.read()
text = content.decode('utf-16')
idx = text.find('quick-actions')
if idx != -1:
print("FOUND using UTF-16!")
print(repr(text[idx:idx+200]))
# Perform replacement
target = '''<button class="btn btn-secondary" onclick="window.location.href='/resources'">Resources</button>'''
if target in text:
replacement = target + '''\n <button class="btn btn-secondary" onclick="window.location.href='/physics'">Physics Room</button>'''
text = text.replace(target, replacement)
with open('studyverse (1).html', 'wb') as f:
f.write(text.encode('utf-16'))
print("Successfully replaced and saved!")
else:
print("Target string not found in UTF-16 text.")
else:
print("NOT FOUND using UTF-16 either.")
except Exception as e:
print(f"Error: {e}")