~martinmassera/beautifulsoup/modifying-string-docs

« back to all changes in this revision

Viewing changes to doc/source/index.rst

  • Committer: Martin Massera
  • Date: 2019-08-22 17:27:11 UTC
  • Revision ID: martinmassera@gmail.com-20190822172711-vfv763tveukd2td2
Adding documentation for parsing HTML content in the "Modifying .string" section

Show diffs side-by-side

added added

removed removed

Lines of Context:
1873
1873
  # <a href="http://example.com/">New link text.</a>
1874
1874
 
1875
1875
Be careful: if the tag contained other tags, they and all their
1876
 
contents will be destroyed.
 
1876
contents will be destroyed. If the new string contains HTML content,
 
1877
it will be escaped and added as the tag's text::
 
1878
 
 
1879
  html_string = "A <strong>BOLD</strong> statement"
 
1880
 
 
1881
  tag.string = html_string
 
1882
  tag
 
1883
  # <a href="http://example.com/">A &lt;strong&gt;BOLD&lt;/strong&gt; statement</a>
 
1884
 
 
1885
You can parse the HTML string by creting a
 
1886
``BeautifulSoap`` object and appending it as tags::
 
1887
 
 
1888
  tag.clear()
 
1889
  tag.append(BeautifulSoup(html_string, 'html.parser'))
 
1890
  tag
 
1891
  # <a href="http://example.com/">A <strong>BOLD</strong> statement</a>
1877
1892
 
1878
1893
``append()``
1879
1894
------------