gpt4 book ai didi

python - 如何从字符串中删除垂直线

转载 作者:太空狗 更新时间:2023-10-30 02:31:15 25 4
gpt4 key购买 nike

<分区>

出于某种原因,我无法从字符串中删除竖线。该字符串是从 html 标签 (BeautifulSoup 4) 中提取的。

该字符串来自站点的标题元标记。

示例输入:'如何跑得非常快 | running.com'
通过if语句,字符串仍然包含|,但在名称中没有检测到,永远不会进入if语句...

name = title.text.encode('ascii', 'ignore').strip()

#remove everything after | because often it is SEO stuff
name = re.sub('\|', '', name) #fails
if "|" in name:
lineIndex = name.index('|')
name = name[:lineIndex]

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com