如何在python中使用BeautifulSoup获得第二个跨度?

问题描述 投票:0回答:4

我正在尝试获取此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等。非常感谢您的帮助,谢谢!

python web-scraping beautifulsoup html-parsing
4个回答
1
投票
尝试一下

0
投票
您基本上有了它,您只需要在每个div(find_next)中获得第二个跨度:

0
投票
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']

0
投票
有几种获取所需值的方法。
© www.soinside.com 2019 - 2024. All rights reserved.