Полный код можно просмотреть здесь: https://pastebin.com/2wK5D6hw
Установите Python. Затем установите следующие две библиотеки с помощью интерпретатора командной строки (cmd) в Windows10:
I have multiple html files in C:Folder1. I have this structure that is repeated in each html files:.
< ! -- $item_id = abc;
After running .py I will get:
In file 1.html I will have $item_id = 1;
In file 2.html I will have $item_id = 2;
In file 3.html I will have $item_id = 3;
...
In file 2300.html I will have $item_id = 2300;КОД: скопируйте и запустите приведенный ниже код в любой программе-интерпретаторе (я использую pyScripter).Не забудьте изменить путь в "incrementare_fisiere_html " линия.
import os import re def read_text_from_file(file_path): """ Aceasta functie returneaza continutul unui fisier. file_path: calea catre fisierul din care vrei sa citesti """ with open(file_path, encoding='utf8') as f: text = f.read() return text def write_to_file(text, file_path): """ Aceasta functie scrie un text intr-un fisier. text: textul pe care vrei sa il scrii file_path: calea catre fisierul in care vrei sa scrii """ with open(file_path, 'wb') as f: f.write(text.encode('utf8', 'ignore')) def incrementare_fisiere_html(cale_folder_html): """ Functia itereaza printr-un folder care contine fisiere html si adauga index-ul corespunzator in fiecare fisier """ count = 0 current_id = 1 for f in os.listdir(cale_folder_html): if f.endswith('.html'): cale_fisier_html = cale_folder_html + "\\" + f html_text = read_text_from_file(cale_fisier_html) item_id_pattern = re.compile('\