擅长:python、mysql、java
<p>最好使用<a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">beautifulSoup</a>或{a2}进行html处理。在</p>
<p>像这样:</p>
<pre><code>from bs4 import BeautifulSoup
html_doc = """
<h1>First header</h1>
<p>first paragraph</p>
<h1>Second header</h1>
<p>second paragraph</p>
<h3>Third header</h3>
"""
soup = BeautifulSoup(html_doc)
for h1 in soup.findAll('h1'):
if h1.find_next_sibling('p'):
h1.insert_after('\nSome text')
print soup
</code></pre>
<p>输出:</p>
^{pr2}$