[Python] Extract span values using BS4

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to extract "Date Applied" and "17 Apr 2025 06:00", from html below:

    <span class="labels" part="text-and-icon-labels">
    <slot part="text-and-icon-label" class="label" data-cy="label">
    <!--?lit$536635879$-->
    Date applied
    </slot>
    <slot part="text-and-icon-sublabel" name="sublabel" class="sublabel">
    <!--?lit$536635879$-->
    17 Apr 2025 06:00
    </slot>
    </span>


    Tried code below on python but doesn't work at all:

    html_ = body.get_attribute('innerHTML')
    soup = BeautifulSoup(html_, "html.parser")
    all_items = soup.find_all('span')
    for item in all_items:
    print(item.text)

    Continue reading...

Compartilhe esta Página