【发布时间】:2021-02-08 20:40:53
【问题描述】:
我试过这个,但我得到这个错误:'UnicodeEncodeError:'charmap'编解码器无法编码位置 286381-286385 中的字符:字符映射到' 导入请求 从 bs4 导入 BeautifulSoup
def main():
f = open("sites.text", 'w')
page = requests.get("https://stackoverflow.com")
soup = BeautifulSoup(page.content, "html.parser")
f.write(str(soup))
f.close()
if __name__ == '__main__':
main()
【问题讨论】:
-
尝试使用
open("sites.text", 'w', encoding='utf8') -
不起作用,给我这个错误:LookupError: unknown encoding: uft8
标签: python html file beautifulsoup