gpt4 book ai didi

python - 属性错误 : 'list' object has no attribute 'replace' when trying to remove character

转载 作者:太空狗 更新时间:2023-10-29 20:13:44 24 4
gpt4 key购买 nike

我正在尝试通过执行以下操作从我的字符串中删除字符 '

kickoff = tree.xpath('//*[@id="page"]/div[1]/div/main/div/article/div/div[1]/section[2]/p[1]/b[1]/text()')
kickoff = kickoff.replace("'", "")

这给了我错误 AttributeError: 'list' object has no attribute 'replace'

我有 php 背景,我不确定这样做的正确方法是什么?

最佳答案

xpath方法返回一个列表,你需要迭代项目。

kickoff = [item.replace("'", "") for item in kickoff]

关于python - 属性错误 : 'list' object has no attribute 'replace' when trying to remove character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36642782/

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