我想更改一些html标签名称。 让我知道python代码的方法。:
按原样
<div class="title-title-1">hello</div>
<div class="text-body">i like you</div>
<div class="p">hehe</div>
<title-title-1>hello</title-title-1>
<text-body>i like you</text-body>
<p>hehe</p>
有人帮助我!!
答案 0 :(得分:0)
<强>演示:强>
maxConnections
<强>输出:强>
from bs4 import BeautifulSoup
s = """<div class="title-title-1">hello</div>
<div class="text-body">i like you</div>
<div class="p">hehe</div>"""
soup = BeautifulSoup(s, "html.parser")
title = soup.find("div", class_="title-title-1").text
body = soup.find("div", class_="text-body").text
p = soup.find("div", class_="p").text
toFrame = """<title-title-1>{0}</title-title-1>
<text-body>{1}</text-body>
<p>{2}</p>""".format(title, body, p)
print(toFrame)