gpt4 book ai didi

python - 由于 Python 和 Selenium 中的元音变音而出现错误

转载 作者:太空宇宙 更新时间:2023-11-03 21:14:32 24 4
gpt4 key购买 nike

目前,我正在尝试使用 Python 重建 Instgram 机器人。

不幸的是,每次运行程序时都会出现错误:

SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe4 in position 23: invalid continuation byte

错误的代码行是:

like_button = lambda: driver.find_element_by_xpath('//span[@aria-label="Gefällt mir"]').click()

该错误是由德语元音变音“ä”引起的,但我必须使用它,因为它是来自“like”按钮的 xpath。

我已经在谷歌上搜索过,找到了将 # --coding: utf-8 -- 放在第一行的解决方案。

不幸的是,这没有帮助。

如果您能给我一些建议,那就太好了。

安团

最佳答案

带变音符号的 a AFAIK 在 UTF8 字符集中无法表示。 https://en.wikipedia.org/wiki/UTF-8

我会尝试使用 ISO-8859-1 作为编码。 https://www.ic.unicamp.br/~stolfi/EXPORT/www/ISO-8859-1-Encoding.html

您可以在代码开头对页面内容进行编码:driver.find_element_by_tag_name('body').get_attribute('innerHTML').encode("ISO-8859-1")

或者在 try/catch 中对元素进行编码以尝试隔离特殊字符。

关于python - 由于 Python 和 Selenium 中的元音变音而出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54816119/

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