所以我尝试编写一个简单的函数来清理文本并对其进行总结:
def getTextWaPo(url):
page = urllib2.urlopen(url).read().decode('utf8')
soup = BeautifulSoup(page, "lxml")
text = ' '.join(map(lambda p: p.text, soup.find_all('article')))
return text.encode('ascii', errors='replace').replace("?"," ")
但是对于这段代码,我收到了这个错误:
File "Autosummarizer.py", line 12, in getTextWaPo
return text.encode('ascii', errors='replace').replace("?"," ")
TypeError: a bytes-like object is required, not 'str'
line 12 ==> text = getTextWaPo(articleURL)
我该怎么办?
桃花长相依
相关分类