Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from re import compile
- def get_all_links(file_contents):
- pattern = compile("<a class=\"entity-link\" data-entity=Actor data-id=.+ ><i class=\"fas fa-user\"></i>.+</a>")
- return pattern.findall(file_contents)
- def fixed_link(link):
- pattern = compile("<a class=\"entity-link\" data-entity=Actor data-id=(.+) ><i class=\"fas fa-user\"></i>(.+)</a>")
- match = pattern.findall(link)
- the_id, name = match[0]
- return f"@Compendium[cos.actors.{the_id}]{{{name}}}"
- with open('data.txt', 'r') as d_file:
- file_content = d_file.read()
- links = get_all_links(file_content)
- for link in links:
- file_content = file_content.replace(link, fixed_link(link))
- with open('outfile.txt', 'w+') as outfile:
- outfile.write(file_content)
Advertisement
Add Comment
Please, Sign In to add comment