【发布时间】:2021-09-01 12:38:35
【问题描述】:
我想删除 ­ 部分。
(­ 是一些编码字符集中保留的代码点,目的是通过插入可见连字符来跨行分隔单词。here)
但是要删除它,我的代码编辑器和 bs4 都无法识别它。
例子:
html示例代码代码:
<span class="lemma__main">Mut­ter</span>
Python 代码:
soup = BeautifulSoup(htmlexample, 'html.parser')
print(soup.find('span', class_='lemma__main').text)
返回:
Mut<0xad>ter
注意: 指的是崇高文本 3 中的空格,但与我尝试替换字符串中的空格时不完全相同, 它只是不识别为一个。 在解释器中它只是一个空格
response.replace(' ', '')
如果我尝试在其中替换 ­,它也不起作用:
response.replace('­','')
都返回:
Mut<0xad>ter
我已经查过了here给出的解决方案
你能帮我解决这个问题吗?
【问题讨论】:
-
print(soup.find('span', class_='lemma__main').text.replace('\xad', ''))为我工作。 -
它有效,谢谢
标签: python html beautifulsoup