Beautiful Soup 获取匹配元素文本内容:.string 方法
在 Beautiful Soup 中,可以使用 .string 方法获取匹配元素的字符串内容。例如:
from bs4 import BeautifulSoup
html = '<p>Hello, world!</p>'
soup = BeautifulSoup(html, 'html.parser')
p_tag = soup.find('p')
print(p_tag.string) # 输出:Hello, world!
原文地址: https://www.cveoy.top/t/topic/oEIf 著作权归作者所有。请勿转载和采集!