可以使用BeautifulSoup库来实现删除超链接但保留文字的操作。

首先,安装BeautifulSoup库:

pip install beautifulsoup4

然后,使用以下代码:

from bs4 import BeautifulSoup

html = '<a href="http://www.example.com">Example</a>'
soup = BeautifulSoup(html, 'html.parser')
for a in soup.find_all('a'):
    a.replace_with(a.text)
print(soup)

输出结果为:

Example

这样就成功删除了超链接,保留了文字。

python 删除超链接保留文字

原文地址: https://www.cveoy.top/t/topic/fPcb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录