不要从BeautifulSoup对象中获取数据。
创始人
2025-01-10 17:00:32
0

Beautiful Soup 仅用于解析 HTML 或 XML 文档,并为您提供易于导航的方法。要从 Beautiful Soup 对象中获取数据,请使用对相应标记/标签及其属性的引用。例如,要获取以标记“span”和类“my-class”表示的元素的文本,可以使用以下代码:

from bs4 import BeautifulSoup

html_doc = """
The Dormouse's story

    

The Dormouse's story

Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well.

...

""" soup = BeautifulSoup(html_doc, 'html.parser') my_element = soup.find('span', {'class': 'my-class'}) if my_element: my_text = my_element.text print(my_text)

请注意,在此示例中,使用了“find”方法在 soup 对象中查找所有具有标记“span”和类“my-class”的元素。如果找到相应的元素,则使用“text”属性访问其文本内容。如果未找到元素,则变量“my_element”将为 None。

相关内容

热门资讯

透视安装!hhpoker免费透... 透视安装!hhpoker免费透视脚本,aapoker可以开挂吗,重大来袭(有挂透明)1、构建自己的微...
透视线上!hhpoker透视脚... 透视线上!hhpoker透视脚本,拱趴大菠萝万能辅助器,可靠技巧(都是真的是有挂)准备好在hhpok...
透视线上!红龙poker透视,... 1、透视线上!红龙poker透视,德扑圈透视,细节方法(往昔有挂);详细教程。2、红龙poker透视...
透视透视!红龙poker辅助,... 透视透视!红龙poker辅助,aapoker有脚本吗,实测交流(有挂教程)是一款可以让一直输的玩家,...
透视挂!wepoker底牌透视... 透视挂!wepoker底牌透视脚本下载,hhpoker到底可以作弊吗,必赢教程(起初真的有挂);支持...
透视app!aapoker辅助... 透视app!aapoker辅助插件工具下载,hhpoker辅助下载,专业讨论(有挂方法)1、每一步都...
透视真的!hhpoker辅助软... 透视真的!hhpoker辅助软件,poker红龙辅助,辅助教程(竟然存在有挂);原来确实真的有挂(需...
透视安装!hhpoker辅助软... 透视安装!hhpoker辅助软件,wepoker底牌透视脚本http,揭秘真相(有挂总结);wepo...
透视好友房!aapoker辅助... 透视好友房!aapoker辅助工具存在吗,wpk德州局怎么透视,揭秘教程(一向是有挂);是一款可以让...
透视模拟器!hhpoker辅助... 透视模拟器!hhpoker辅助软件,hhpoker透视脚本安卓,分享给玩家(有挂攻略)是一款可以让一...