[Python] extract text not part of inner division

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

  1. Stack

    Stack Membro Participativo

    I have this code that extracts too much text. I am trying to extract only the title from top-content.

    from bs4 import BeautifulSoup
    import requests
    r = requests.get("https://education.maharashtra.gov.in/saral/27230500360")
    data = r.text
    soup = BeautifulSoup(data)
    soup.find("div", {"class": "top-content"})


    How do I extract the name of school that is not part of inner div? Expected output:

    BHARATI VIDYAMANDIR HINDI NIGHT HIGH SCHOOL AND JR COLLEGE (27230500360)


    update:

    Is it possible to save the text as dict?

    {27230500360 : "BHARATI VIDYAMANDIR HINDI NIGHT HIGH SCHOOL AND JR COLLEGE"}

    Continue reading...

Compartilhe esta Página