[英]how to remove the starting and ending tags using python Beautiful soup
我很難從 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)
所以感謝德米安狼。 解決方案是這樣的:
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)
您可以使用soup.text
刪除所有標簽:
from bs4 import BeautifulSoup
soup = BeautifulSoup("<pre>Hello, world!</pre>", "html.parser")
print(soup.find("pre").text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.