Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python BeautifulSoup4中,如何提取这样的特殊文本_Python_Beautifulsoup - Fatal编程技术网

在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