Last active
April 13, 2017 22:01
-
-
Save c0nstantine/6456660ed181c37633cc47925b55c060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> hr = BeautifulSoup('<p>first</p><hr><p>second</p><p>third</p>', 'html.parser') | |
>>> hr2 = BeautifulSoup('<p>first</p><hr/><p>second</p><p>third</p>', 'html.parser') | |
>>> | |
>>> for p in hr.find_all('p'): | |
... p.insert_after(hr.new_string('<div class="ad"></div>')) | |
... | |
>>> for p in hr2.find_all('p'): | |
... p.insert_after(hr2.new_string('<div class="ad"></div>')) | |
... | |
>>> | |
>>> hr.contents | |
[<p>first</p>, u'<div class="ad"></div>', <hr><p>second</p><div class="ad"></div><p>third</p><div class="ad"></div></hr>] | |
>>> hr2.contents | |
[<p>first</p>, u'<div class="ad"></div>', <hr/>, <p>second</p>, u'<div class="ad"></div>', <p>third</p>, u'<div class="ad"></div>'] | |
>>> | |
=== | |
>>> hr = BeautifulSoup('<p>first</p><hr><p>second</p><p>third</p>', 'html.parser') | |
>>> hr2 = BeautifulSoup('<p>first</p><hr/><p>second</p><p>third</p>', 'html.parser') | |
>>> | |
>>> hr | |
<p>first</p><hr><p>second</p><p>third</p></hr> | |
>>> hr2 | |
<p>first</p><hr/><p>second</p><p>third</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment