当我尝试从“url”中抓取一些带有 Finish-Names 的文本时,出现上述错误。我尝试过的解决方案和相应的错误,在代码中注释如下。我既不知道如何解决这些问题,也不知道确切的问题是什么。我是 Python 初学者。任何帮助表示赞赏。
我的代码:
from lxml import html
import requests
page = requests.get('url')
site = page.text # ERROR -> 'charmap' codec can't encode character '\x84' in
# position {x}: character maps to <undefined>
# site = site.encode('utf-8', errors='replace') # ERROR -> can't concat str to bytes
# site = site.encode('ascii', errors='replace') # ERROR -> can't concat str to bytes
with open('url.txt', 'a') as file:
try:
file.write(site + '\n')
except Exception as err:
file.write('an ERROR occured: ' + str(err) …Run Code Online (Sandbox Code Playgroud)