Trying to encode the text output received after parsing HTML data through BeautifulSoup library in Python 3. Getting following error:
----> gmtext.encode('ascii', errors='replace').replace("?", "")
TypeError: a bytes-like object is required, not 'str'
Here is the code implementation:
import urllib.request as urllib2
from bs4 import BeautifulSoup
articleURL = "http://digimon.wikia.com/wiki/Guilmon"
page = urllib2.urlopen(articleURL).read().decode('utf8', 'ignore')
soup = BeautifulSoup(page, 'lxml')
gmtext = soup.find('p').text
gmtext.encode('ascii', errors='replace').replace("?", "")
So far, all answers I found regarding this error have been about some sort of file open error.