25
16
9
4
1
0
这是我的代码:
<li class="latest-value-item">
<div class="latest-value-label">Date</div>
<div class="latest-value">2017-06-01</div>
</li>
<li class="latest-value-item">
<div class="latest-value-label">Index</div>
<div class="latest-value">1430</div>
</li>
答案 0 :(得分:3)
date = soup.find_all(class_="latest value")
您使用了错误的CSS类名称('latest value' != 'latest-value'
)
print(soup.find_all(attrs={'class': 'latest-value'}))
# [<div class="latest-value">2017-06-01</div>, <div class="latest-value">1430</div>]
for element in soup.find_all(attrs={'class': 'latest-value'}):
print(element.text)
# 2017-06-01
# 1430
我更喜欢使用attrs
kwarg,但您的方法也适用(给定正确的CSS类名称)
for element in soup.find_all(class_='latest-value'):
print(element.text)
# 2017-06-01
# 1430