首页 > 解决方案 > 如何使用python去除开始和结束标签 美丽的汤

问题描述

我很难从 json url 中剥离开始和结束标签。我用过漂亮的汤,我面临的唯一问题是<pre>我的回复中有标签。请告知我如何删除开始和结束标签。我正在使用的代码块在这里:

page = Page( "link to json")
soup = bs.BeautifulSoup(page.html, "html.parser")
#fetching the response i want from the url it's inside pre tags.
json = soup.find("pre")
print(json)

标签: pythonbeautifulsoup

解决方案


所以感谢德米安狼。解决方案是这样的:

page = Page( "link to json")
soup = bs.BeautifulSoup(page.html, "html.parser")
#fetching the response i want from the url it's inside pre tags.
json = soup.find("pre")
print(json.text)

推荐阅读