-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirect_replace_github.py
More file actions
36 lines (27 loc) · 1.18 KB
/
direct_replace_github.py
File metadata and controls
36 lines (27 loc) · 1.18 KB
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
28
29
30
31
32
33
34
35
36
with open(r"c:\Users\assdr\Desktop\New Project\index.html", "r", encoding="utf-8") as f:
content = f.read()
# Find GH position
gh_idx = content.find('<div class="social-txt-1">GH</div>')
if gh_idx != -1:
# Get 500 chars before GH to see the full link structure
start = max(0, gh_idx - 500)
context = content[start:gh_idx + 100]
print("Context around GH:")
print(repr(context))
# Now find the href in this context
import re
href_matches = re.findall(r'href="([^"]*)"', context)
if href_matches:
print(f"\nFound hrefs: {href_matches}")
# The last href before GH should be the one we want
current_github_url = href_matches[-1]
print(f"Current URL: {current_github_url}")
# Replace it
content = content.replace(
f'href="{current_github_url}"',
f'href="https://github.com/Bishaldgr8"',
1 # Only replace first occurrence
)
with open(r"c:\Users\assdr\Desktop\New Project\index.html", "w", encoding="utf-8") as f:
f.write(content)
print(f"\nReplaced {current_github_url} with https://github.com/Bishaldgr8")