~leonardr/beautifulsoup/bs4

« back to all changes in this revision

Viewing changes to doc/source/index.rst

  • Committer: Leonard Richardson
  • Date: 2020-01-01 18:30:28 UTC
  • Revision ID: leonardr@segfault.org-20200101183028-k1j9xid384tzbu0k
API CHANGE - Added PageElement.decomposed, a new property which lets you
  check whether you've already called decompose() on a Tag or
  NavigableString.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
 #     Lacie
98
98
 #    </a>
99
99
 #    and
100
 
 #    <a class="sister" href="http://example.com/tillie" id="link2">
 
100
 #    <a class="sister" href="http://example.com/tillie" id="link3">
101
101
 #     Tillie
102
102
 #    </a>
103
103
 #    ; and they lived at the bottom of a well.
2067
2067
  markup = '<a href="http://example.com/">I linked to <i>example.com</i></a>'
2068
2068
  soup = BeautifulSoup(markup)
2069
2069
  a_tag = soup.a
2070
 
 
2071
 
  soup.i.decompose()
2072
 
 
 
2070
  i_tag = soup.i
 
2071
 
 
2072
  i_tag.decompose()
2073
2073
  a_tag
2074
2074
  # <a href="http://example.com/">I linked to</a>
2075
2075
 
 
2076
The behavior of a decomposed ``Tag`` or ``NavigableString`` is not
 
2077
defined and you should not use it for anything. If you're not sure
 
2078
whether something has been decomposed, you can check its
 
2079
``.decomposed`` property (new in 4.9.0)::
 
2080
 
 
2081
  i_tag.decomposed
 
2082
  # True
 
2083
 
 
2084
  a_tag.decomposed
 
2085
  # False
 
2086
 
2076
2087
 
2077
2088
.. _replace_with():
2078
2089