我正在尝试获取此div和其他类似的div值(如下所示)
<div class="C(#959595) Fz(11px) D(ib) Mb(6px)">
<span>VALUE 1</span>
<i aria-hidden="true" class="Mx(4px)">•</i>
<span>TRYING TO GET THIS</span>
</div>
我曾尝试查看类似的堆栈文章,但仍然不知道如何解决此问题。这是我当前的代码:
time = soup.find_all('div', {'class': 'C(#959595) Fz(11px) D(ib) Mb(6px)'})
for i in time:
print(i.text) #this prints VALUE 1 x amount of times (there are multiple divs)
我尝试过i.span,i.contents,i.children等。非常感谢您的帮助,谢谢!
div= soup.find_all('div',class_='C(#959595) Fz(11px) D(ib) Mb(6px)')
[x.get_text() for x in div[0].find_all('span')]
#op
Out[17]:
['VALUE 1', 'TRYING TO GET THIS']