來源:
html="""<!-- End Ezoic - under page title - under_page_title -->
</div> <!-- LEFTCOL END -->
<p> The first sentence is sentence A.
Sentence B has information pertaining about sentence A.
<br><br>Below here is irrelevant..."""
當我輸入
import re
match_results = re.search("The first sentence.*", html, re.IGNORECASE)
print(match_results.group(0))
它回傳
The first sentence is sentence A.
我如何也得到以下句子,以便預期的輸出是
The first sentence is sentence A. Sentence B has information pertaining about sentence A.
uj5u.com熱心網友回復:
由于資料沒有任何明確的模式,您可以通過匹配直到第一行<與“第一句[^<]*”來獲得第二行。
import re
html="""<!-- End Ezoic - under page title - under_page_title -->
</div> <!-- LEFTCOL END -->
<p> The first sentence is sentence A.
Sentence B has information pertaining about sentence A.
<br><br>Below here is irrelevant..."""
match_results = re.search("The first sentence[^<]*", html, re.IGNORECASE)
print(match_results.group(0))
#The first sentence is sentence A.
#Sentence B has information pertaining about sentence A.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458777.html
