Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在.txt文件中打印单引号会变成奇怪的字符_Python_Selenium - Fatal编程技术网

Python 在.txt文件中打印单引号会变成奇怪的字符

Python 在.txt文件中打印单引号会变成奇怪的字符,python,selenium,Python,Selenium,我使用Selenium刮取一些句子,然后将结果打印到.txt文件中,但它不能显示,,而是显示一些奇怪的字符: 原文: I don't think so. 在.txt文件中: I don? think so. 我已经将.txt编码指定为“utf-8”,我应该怎么做?您需要打开文件以在“utf-8”中写入: with open("file.txt", "w", encoding="utf-8") as file file.write("your_text") 希望它能帮助你

我使用Selenium刮取一些句子,然后将结果打印到.txt文件中,但它不能显示
,而是显示一些奇怪的字符:

原文:

I don't think so.
在.txt文件中:

I don? think so.

我已经将.txt编码指定为“utf-8”,我应该怎么做?

您需要打开文件以在“utf-8”中写入:

with open("file.txt", "w", encoding="utf-8") as file

    file.write("your_text")
希望它能帮助你