【问题标题】:Handle o:p tag in BeautifulSoup在 BeautifulSoup 中处理 o:p 标签
【发布时间】:2020-01-09 06:33:56
【问题描述】:

我正在从http://people.dbmi.columbia.edu/~friedma/Projects/DiseaseSymptomKB/index.html提取一些疾病信息

但数据包含在我不知道如何处理的标签中。

我发现的一种方法是使用 find_all 函数,但有什么方法可以作为 tr.td.span.[o:p or something] 吗??


<td width="584" nowrap="" valign="top" style="width:438.0pt;padding:0in 5.4pt 0in 5.4pt;
  height:12.75pt">
  <p class="MsoNormal"><span style="font-size:10.0pt;font-family:&quot;Arial&quot;,&quot;sans-serif&quot;">UMLS:C0008031_pain
  chest
<o:p>&nsp</o:p>
</span>
</p>
  </td>

【问题讨论】:

  • 我试图了解您要提取的内容以及问题所在,但我还无法达到目的
  • @αԋɱҽԃαмєяιcαη 我需要知道 o:p 标签内的内容
  • 在下面查看我的答案

标签: html beautifulsoup


【解决方案1】:
import pandas as pd

df = pd.read_html(
    "http://people.dbmi.columbia.edu/~friedma/Projects/DiseaseSymptomKB/index.html")[0]

df.to_csv("out.csv", index=False, header=False)

输出:view-online

以防万一你想要全桌。

但根据您的要求。

用途:

import pandas as pd

df = pd.read_html(
    "http://people.dbmi.columbia.edu/~friedma/Projects/DiseaseSymptomKB/index.html")[0]

print(df[2][1:].values.tolist())

对于bs4

使用

import requests
from bs4 import BeautifulSoup

r = requests.get(
    "http://people.dbmi.columbia.edu/~friedma/Projects/DiseaseSymptomKB/index.html")


soup = BeautifulSoup(r.text, 'html.parser')

for item in soup.findAll("p", {'class': 'MsoNormal'}):
    item = item.get_text(strip=True)
    if item.startswith("UMLS"):
        print(item)

【讨论】:

    猜你喜欢
    • 2010-12-29
    • 1970-01-01
    • 2019-06-15
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-06
    • 2012-09-27
    相关资源
    最近更新 更多