我需要从我的总p元素中拉出一个跨度元素
下面是我正在解析的一个p元素的具体示例
<p id="p-9">
<span class="inline-l2-heading">H5N1 virus pathogenic phenotypes among
inbred mouse strains.
</span>
We experimentally inoculated 21 mouse strains with the highly
pathogenic H5N1 influenza A virus A/Hong Kong/213/03 (HK213)
and monitored the animals for 30 days thereafter for signs of
morbidity and mortality. The 50% mouse lethal dose (MLD<sub>50</sub>)
values varied from 40 50% egg infective doses (EID<sub>50</sub>)
for the influenza virus-susceptible strain DBA/2<sub>S</sub>
(susceptibility indicated by “S”) to more than 10<sup>6</sup>
EID<sub>50</sub> for the influenza virus-resistant strains
BALB/c<sub>R</sub> and BALB/cBy<sub>R</sub>
(resistance indicated by “R”) (<a class="xref-fig" href="#F1" id="xref-fig-1-
1">Fig. 1</a>).
</p>
如果我将变量段落作为bs4.element.Tag并执行此操作
print(paragraph.text)
结果是
H5N1 virus pathogenic phenotypes among inbred mouse strains.We experimentally
inoculated 21 mouse strains with the highly pathogenic H5N1 influenza A virus
A/Hong Kong/213/03 (HK213) and monitored the animals for 30 days thereafter
for signs of morbidity and mortality. The 50% mouse lethal dose (MLD50)
values varied from 40 50% egg infective doses (EID50) for the influenza
virus-susceptible strain DBA/2S (susceptibility indicated by “S”) to more
than 106 EID50 for the influenza virus-resistant strains BALB/cR and
BALB/cByR (resistance indicated by “R”) (Fig. 1).
正如你在第一句和第二句中所看到的,它没有在跨度中的文本和段落其余部分中的文本之间创建空格
它最终看起来像:
“近交系小鼠中的H5N1病毒致病表型。我们在实验上……”
正如你所看到的,这导致两个独立的句子在句号后没有空格,这是一个很大的问题,因为我稍后将逐句拆分,大多数分句器用句号和空格分隔,我的大多数其他句子都是正确形成的
有没有什么方法可以用bs4将跨度中的文本与其余文本隔离开来,然后用适当的间距将它们连接在一起
另一个解决方案:
印刷品:
我假设您正在使用} 的操作。这将给出一个包含所有字符串的数组。然后您可以
get_result()
。您可以在bs4中执行另一个名为^{join
将它们放在一起以获得正确格式的文本:另外,在您的示例中,我看到有很多空白用于格式化。你可以通过做
stripped_strings
来摆脱这些尝试:
印刷品:
等等
相关问题 更多 >
编程相关推荐