[英]How to unwrap tag from a BeautifulSoup Tag object?
我有一个 BeautifulSoup Tag 对象,它看起来像这样
<p>This is an example of something that I'm <strong>confused</strong> about</p>
我想获得
This is an example of something that I'm <strong>confused</strong> about
看起来这应该是 BeautifulSoup 中 .unwrap() 之类的简单应用,但我尝试的每件事都不起作用。 我能帮上忙吗?
像 BeautifulSoup 中的 .unwrap() 之类的东西,但我尝试的每件事都不起作用
unwrap()
修改soup
对象本身,查看结果,打印soup
:
soup = BeautifulSoup(html, "html.parser")
soup.find("p").unwrap()
print(soup)
输出:
This is an example of something that I'm <strong>confused</strong> about
尝试 .renderContents() 方法:
text = soup.find('p').renderContents()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.