Python BeautifulSoup extract certain information after located text?

Discussion in 'Programming' started by razodiac, Aug 8, 2021.

  1. #1
    From

    <div class="peoples-info">
    <ul>
    <li><strong>Gender:</strong> F</li>
    <li><strong>Birthdate:</strong> 00/00/2000</li>
    <li><strong>Family Phone:</strong> 000-000-0000</li>
    <li><strong>Personal Phone:</strong> 000-000-0000</li>
    </ul>
    </div>
    </div>
    <div>
    Code (markup):
    I want to extract using BeautifulSoup's find_next function, but I could only do tables such as:

    for gender in soup.find('td', text='gender:'):
    print(gender.find_next("td").text)
    Code (markup):
    Which does not work with div when I replace "td" with "li"; also, title and number are in the same line with only the format changed a bit. Is there a way to extract only information such as phone numbers and birthdays without their titles ("000-000-0000")? Thanks!
     
    razodiac, Aug 8, 2021 IP