Python(3.8.2) - 将 selenium(3.141.0) 网络元素特殊字符转换为字符串

Python(3.8.2) - convert selenium(3.141.0) web element special character to string

我正在尝试在某种初学者 crawler/bot 程序中将 Web 元素转换为字符串。

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('https://www.wuxiaworld.com/novel/against-the-gods/atg-chapter-1')
chapter_content = browser.find_elements_by_id('chapter-content')
with open('ATG.txt', 'w') as fp:
    for i in chapter_content:
        fp.write(i.text)
browser.quit()

一切顺利,因为正在编写文本,但每当出现诸如“!”之类的字符时或遇到 '-' 输出仅显示 �

例如; 预期输出应为

Chapter 1 - Yun Che, Xiao Che

但是它显示,

Chapter 1 � Yun Che, Xiao Che

不胜感激!!

尝试

open('ATG.txt', 'w', encoding='utf-8')

而不是

open('ATG.txt', 'w'')