擅长:python、mysql、java
<p>也许您可以使用<code>re</code>模块。参考参见<a href="https://docs.python.org/2/howto/regex.html" rel="nofollow noreferrer">Regular Expression Howto for py2</a></p>
<pre><code>str_tags = """
<i>Hello<\i>
<a href="www.google.com"> Google <\a>
<i>Bye<\i>
<a href="www.google.com"> Google2 <\a>
<i>Hello<\i>
<a href="www.google.com"> Google3 <\a>
<i>Bye<\i>
"""
import re
str_re = re.compile(r".*Hello.*\s<a[^>]*>([\w\s]+)<\a>\s<i>Bye")
content_lst = str_re.findall(str_tags)
if content_lst:
print(content_lst)
else:
print("Not found")
</code></pre>
<p>输出</p>
<blockquote>
<p>[' Google ', ' Google3 ']</p>
</blockquote>
<p>注意这个方法很大程度上取决于html的外观。
有关以上代码的说明,请参阅第一个链接。在</p>