从临床试验中获取数据

2024-06-17 15:10:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个小Python函数来从clinicalTrials.gov中获取数据。从每个研究记录中,我想从中找出研究的目标条件。例如,对于this研究记录,我需要以下内容:

conditions = ['Rhinoconjunctivitis', 'Rhinitis', 'Conjunctivitis'. 'Allergy']

然而,在每个研究记录中,有不同数量的情况。我写了以下脚本来获取数据:

^{pr2}$

是这样的:

b'Condition or disease'
b'Intervention/treatment'
b'Phase'
b'Rhinoconjunctivitis'
b'Rhinitis'
b'Conjunctivitis'
b'Allergy'
b'Drug: Placebo'
b'Biological: SCH 697243'
b'Drug: Loratadine Syrup 1 mg/mL Rescue Treatment'
b'Drug: Loratadine 10 mg Rescue Treatment'
b'Drug: Olopatadine 0.1% Rescue Treatment'
b'Drug: Mometasone furoate 50 mcg Rescue Treatment'
b'Drug: Albuterol 108 mcg Rescue Treatment'
b'Drug: Fluticasone 44 mcg Rescue Treatment'
b'Drug: Prednisone 5 mg Rescue Treatment'
b'Phase 3'

我现在怎么能在没有干预/治疗信息的情况下只得到病情?在


Tags: 函数记录情况treatmentphasemgrescuedrug
2条回答

您只需将第一个table与类data_table&extractspan元素一起使用在td中:

import requests
from bs4 import BeautifulSoup

page = requests.get('https://clinicaltrials.gov/ct2/show/study/NCT00550550')
soup = BeautifulSoup(page.text, 'html.parser')
studyDesign = soup.find("table", {"class" : "data_table"}).find('td')
conditions = [ t.text.strip() for t in studyDesign.find_all('span') ]
print(conditions)

它给出了:

^{pr2}$

也许这个代码会有所帮助。在

import requests
from bs4 import BeautifulSoup

#url = "https://clinicaltrials.gov/ct2/show/NCT02656888"
url = "https://clinicaltrials.gov/ct2/show/study/NCT00550550"

page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
table = soup.find_all("table", class_="data_table")

tds = [tr.find_all("td") for tr in table]
conditions = [condition for condition in (tds[0][0].get_text().split("\n")) if condition != ""]

print(conditions)

相关问题 更多 >