I have a collection of HTML files. I want to iterate over them one by one, editing the label of a certain class. The code I want to change is as follows using the following class names:
<td class='thisIsMyClass' colspan=4> <a id='123' class='thisIsMyOtherClass' href='123'>Put me Elsewhere</a>
This can happen several times in the same document with different text instead of “Put me in another place”, but always the same classes.
I want to change this as a form:
<font SIZE="3" COLOR="#333333" FACE="Verdana" STYLE="background-color:#ffffff;font-weight: bold;"> <h2>Put Me Elsewhere</h2> </font>
import os for filename in os.listdir('dirname'): replace(filename) def replace(filename): tags = soup.find_all(attrs={"thisIsMyClass"})
Not too sure where to go after this or how to deal with an array of tags? Any help is appreciated. Thanks:)
source share