在Python BeautifulSoup4中,如何提取这样的特殊文本
我正试图提取一些字符串。从本文中:在Python BeautifulSoup4中,如何提取这样的特殊文本,python,beautifulsoup,Python,Beautifulsoup,我正试图提取一些字符串。从本文中: text = "<li>(<a rel="nofollow" class="external text" href="http://www.icd9data.com/getICD9Code.ashx? icd9=999.1">999.1</a>) <a href="/wiki/Air_embolism" title="Air embolism">Air embolism</a> as
text = "<li>(<a rel="nofollow" class="external text" href="http://www.icd9data.com/getICD9Code.ashx?
icd9=999.1">999.1</a>) <a href="/wiki/Air_embolism" title="Air embolism">Air embolism</a> as
a complication of medical care not elsewhere classified</li>"
任何人知道任何方法都可以调用我想要的字符串吗?
谢谢
印刷品
(999.1) Air embolism as
a complication of medical care not elsewhere classified
get_text
方法返回标记中的所有文本,甚至是子标记的一部分
使用,你可以使用
import lxml.html as LH
text = """<li>(<a rel="nofollow" class="external text" href="http://www.icd9data.com/getICD9Code.ashx?
icd9=999.1">999.1</a>) <a href="/wiki/Air_embolism" title="Air embolism">Air embolism</a> as
a complication of medical care not elsewhere classified</li>"""
doc = LH.fromstring(text)
for tag in doc.xpath('//li/a[2]'):
print(tag.tail)
(999.1) Air embolism as
a complication of medical care not elsewhere classified
import lxml.html as LH
text = """<li>(<a rel="nofollow" class="external text" href="http://www.icd9data.com/getICD9Code.ashx?
icd9=999.1">999.1</a>) <a href="/wiki/Air_embolism" title="Air embolism">Air embolism</a> as
a complication of medical care not elsewhere classified</li>"""
doc = LH.fromstring(text)
for tag in doc.xpath('//li/a[2]'):
print(tag.tail)
as
a complication of medical care not elsewhere classified