Beautiful Soup 'ResultSet' object has no attribute 'text'

前端 未结 3 856
孤独总比滥情好
孤独总比滥情好 2021-01-12 10:51
from bs4 import BeautifulSoup
import urllib.request
import win_unicode_console
win_unicode_console.enable()


link = (\'https://pietroalbini.io/\')  
req = urllib.re         


        
3条回答
  •  情歌与酒
    2021-01-12 11:29

    Probably should have posted as answer.. so as stated in the comments almost verbatim

    Your code should be the following:

    for div in body: 
        print div.text
        #python3
        #print(div.text)
    

    Or some naming schema to your preference thereof.

    The find_all method returns a generated list ( loosely using the term list here ) of items that beautifulsoup has found matching your criteria after parsing the source webpages html either recursively or non-recursively depending upon how you search.

    As the error says the resulting set of objects has no attribute text, since it isn't an element but rather a collection of them. However, the items inside the resulting set ( should any be found ) do.

    You can view the documentation here

提交回复
热议问题