Jun-28-2023, 08:25 AM
import re # Citește conținutul fișierului new-file.html with open('c:/Folder7/new-file.html', 'r') as file: first_code = file.read() # Citește conținutul fișierului old-file.html with open('c:/Folder7/old-file.html', 'r') as file: second_code = file.read() # Extrage URL-ul din first_code match = re.search('<a href="(.*?)" title="View all articles', first_code) if match is not None: url = match.group(1) # Înlocuiește URL-ul în second_code second_code = re.sub(', in <a href=".*?" title="Vezi toate', f', in <a href="{url}" title="Vezi toate', second_code) # Scrie conținutul modificat înapoi în old-file.html with open('c:/Folder7/old-file.html', 'w') as file: file.write(second_code) else: print("No match found")