unicode error in .prettify() python 3 -
i'm trying scrape websites using requests , beautifulsoup4 packages.
>>>import requests >>>from bs4 import beautifulsoup >>>r = requests.get('https://www.yellowpages.com/search?search_terms = coffee&geo_location_terms=los+angeles%2c+ca') >>>r.content #shows source code (mess) bytes type >>>soup = beautifulsoup(r.content,'html.parser') when try prettify , display html code of page
print(soup.prettify())
i error
unicodeencodeerror: 'charmap' codec can't decode character '\u2013' in position 44379: character maps <undefined> i tried
>>>soupbytes = soup.prettify(encoding = 'utf-8') #this bytes format >>>soupstr = soupbytes.decode('utf-8') #this str format with first 1 don't problem print (print(soupbytes)), doesn't print text 'pretty', , bytes format. if try print second 1 (print(soupstr)) error again object in str type.
i have don't error in ide (spyder). it's say, if run next code in spyder:
import requests bs4 import beautifulsoup r = requests.get('https://www.yellowpages.com/search? search_terms=coffee&geo_location_terms=los+angeles%2c+ca') r.content #muestra html de la pagina soup = beautifulsoup(r.content,'html.parser') print(soup.prettify()) i don't have error , printed nicely. why difference? , how avoid error in terminal???
Comments
Post a Comment