How to add new value to a class with lxml

not sure if its even possible tbh.. all im trying to do is dynamically edit the text.

HTML:

 <aside class="banner">
            Place <span class=red>open</span></a>
        </aside>

python:

reds = root.find_class("red")
for element in reds:
    *not sure what goes here*

I already have code that i can use to edit the text remotel

Answer

I know you are asking about lxml but great alternative when it comes to html files is bs4.

With bs4/BeautifulSoup it looks like this:

for element in soup.find_all("span", { "class": "red"}):
    element.string = NEW_VALUE

with open("out.html", "w") as out_file:
    out_file.write(str(soup))

https://github.com/poleszcz/stack-misc/blob/main/69193852-bs4-edit-content/edit.py