擅长:python、mysql、java
<p>你可以试试正则表达式:</p>
<pre><code>import re
t = """Item 1a.Risk Factors
not any text (unwanted portion)
Item 1b
End of table of contents
Main content
Item 1a. Risk Factors
text (wanted portion)
text (wanted portion)
text (wanted portion)
Item 1b"""
crit = re.compile('Item 1a.Risk Factors.*?Item 1a. Risk Factors(.*?)Item 1b', re.I|re.DOTALL)
if re.search(crit, t):
result = re.search(crit, t).group(1)
</code></pre>