<p class="mrgn-bttm-0 pop text-center" title="Chance of Precipitation"><small> 30%</small></p>
我想从上面的示例p标签中提取“降低30%的可能性”。实际上有14个这样的标签,每天一个。我使用了所有的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'])
但我无处可去。有人可以协助吗?
答案 0 :(得分:0)
试试这个:
f = soup.find('details', {'class':"panel panel-default wxo-fcst"})
for i in f.find_all('p',{'class':'mrgn-bttm-0 pop text-center'}):
print i['title']+" "+i.get_text().strip()
输出:
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation 60%
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation
Chance of Precipitation 60%