urlopen
返回字节流而不是字符串,并且
.split()
对那些对象不可用。您需要首先根据正确的字符集对其进行解码:
from urllib.request import urlopen
#Reading the text of novel from a website
huck_fin_url = 'http://www.gutenberg.org/files/76/76-0.txt'
df = urlopen(huck_fin_url)
huck_fin_text = df.read().decode("utf8")
#print(huck_fin_text)
huck_fin_chapters = huck_fin_text.split('CHAPTER ')[1:]