[英]How to find words from a wordlist in a HTML/JS code stored in .txt file through a python program?
是的,所以我正在制作一個python程序來查找可以隱藏在網頁源代碼中的某些單詞。 到目前為止,當我在源代碼上運行我的程序時,這個錯誤突然出現
a = f1.read()
File "C:\Program Files (x86)\Python38-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 53198: character maps to <undefined>
這是我的python程序:
with open("G:/EncredX/sourcecode.txt") as f1:
a = f1.read()
print(a)
if("word" in a):
print("word")
如果文件使用另一種編碼,而打開的默認編碼將取決於平台,則會發生此錯誤。 用:
with open("G:/EncredX/sourcecode.txt", encoding="latin1") as f1:
或者
with open("G:/EncredX/sourcecode.txt", encoding="utf8") as f1:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.