擅长:python、mysql、java
<p>您可以使用<code>BeautifulSoup</code>进行html解析。</p>
<pre><code>input = """"<person>John</person>went to<location>London</london>"""
soup = BeautifulSoup(input)
print soup.findAll("person")[0].renderContents()
print soup.findAll("location")[0].renderContents()
</code></pre>
<p>另外,在python中使用<code>str</code>作为变量名并不是一个好的实践,因为<code>str()</code>在python中意味着不同的东西。</p>
<p>顺便说一下,regex可以是:</p>
<pre><code>import re
print re.findall("<person>(.*?)</person>", input)
print re.findall("<location>(.*?)</location>", input)
</code></pre>