[Python] Beautiful Soup 'ResultSet' object has no attribute 'text'

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    from bs4 import BeautifulSoup
    import urllib.request
    import win_unicode_console
    win_unicode_console.enable()


    link = ('https://pietroalbini.io/')
    req = urllib.request.Request(link, headers={'User-Agent': 'Mozilla/5.0'})
    url = urllib.request.urlopen(req).read()

    soup = BeautifulSoup(url, "html.parser")
    body = soup.find_all('div', {"class":"wrapper"})

    print(body.text)


    I have a problem with Beautiful Soup. If I run this code without ".text" at the end it shows me a list of divs but if I add ".text" at the end I get the error

    Traceback (most recent call last):
    File "script.py", line 15, in <module>
    print(body.text)
    AttributeError: 'ResultSet' object has no attribute 'text'

    Continue reading...

Compartilhe esta Página