源码:
# coding: UTF-8 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') data = soup.find('p', {'class': 'story'}) print(data)
输出:
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.
问题:我想爬取的是 p 标签下的 属性值为 story 的 class, 但是结果怎么出来有 a 标签呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个是正常的,是
标签的子元素。