>>> from bs4 import BeautifulSoup
>>> sample = '''\
... <section id="about" class="about-section">
... <div class="container">
... <div class="row">
... <div class="col-lg-12">
... <h1>About Section</h1>
...
... <p class = "test-message-one"> Hey </p>
...
... </div>
... </div>
... </div>
... </section>
... '''
>>> soup = BeautifulSoup(sample)
>>> test = soup.find_all(class_='test-message-one')
>>> print(test)
returns
[<p class="test-message-one"> Hey </p>]
How do I replace the contents 'Hey' with a string saved in python?
I need the HTML to be overwritten with a varibale that I have saved - but most of the documenation I understand in BS4 only shows how to change the name of the class - not the content itself.
Lets say I have this string in python:
>>> replace=('Testing...123')
How do I get it to write back over the HTML to this:
>>> from bs4 import BeautifulSoup
>>> sample = '''\
... <section id="about" class="about-section">
... <div class="container">
... <div class="row">
... <div class="col-lg-12">
... <h1>About Section</h1>
...
... <p class = "test-message-one"> Testing...123 </p>
...
... </div>
... </div>
... </div>
... </section>
... '''