美化对汤有效,但对汤无效1=汤。全部查找

2024-10-02 04:26:24 发布

您现在位置:Python中文网/ 问答频道 /正文

MyAlphaSoup = BeautifulSoup(website_to_crawl.text, 'html.parser')

MyAlphaSoup.prettify()

MyAlphaAlphaSoup = MyAlphaSoup.find_all("div", {"class": "lister-item featurefilm"})

MyAlphaAlphaSoup.prettify()

我在第四行出错了

raise AttributeError( AttributeError: ResultSet object has no attribute 'prettify'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

难道汤不都只是把汤缩小到一个较小的子集吗?所以类型没有改变

Error

Code Pic


Tags: totextyouparserhtmlwebsiteallfind
1条回答
网友
1楼 · 发布于 2024-10-02 04:26:24

这是因为函数find_all返回一个列表。因此,如果指定列表的元素或循环,您应该能够做到这一点:

my_alpha_soup = BeautifulSoup(website_to_crawl.text, 'html.parser')

my_alpha_soup.prettify()

list_of_elements = my_alpha_soup.find_all("div", {"class": "lister-item featurefilm"})

for element in list_of_elements:
    print(element.prettify())

此外,还有一个惯例,即只对类使用首字母大写

相关问题 更多 >

    热门问题