1
<p class="mrgn-bttm-0 pop text-center" title="Chance of Precipitation"><small> 30%</small></p>
我想从上面的示例p标记中提取“Chance of Precipitation 30%”。其中有14个标签,每天一个。我使用了所有的p标签;如何从P标记中提取标题
f = soup.find('details', {'class':"panel panel-default wxo-fcst"})
然后我曾尝试:
for i in f:
print i.find('p')['title']
和
for i in x.findAll("p"):
print i.find('p')['title'])
但我越来越行不通。有人可以协助吗?
尝试'[P [ '标题'] + p.text.strip(),用于f.findAll P('P “)]'? – Psidom
在例子中,你有class =“mrgn-bttm-0弹出文本中心”,但你正在调整变量“f”'class':“panel panel-default wxo-fcst” – Zydnar
using your suggestion I get“Exception is '标题'”。我正试图从https://weather.gc.ca/city/pages/ab-52_metric_e.html浏览数据。 f = soup.find('details',{'class':“panel panel-default wxo-fcst”})为我提供了所有我想要从中获得的标题。 –