UnicodeEncodeError: 'ascii' codec can't encode character '\u2013' in position 13: ordinal not in range(128)
I have used the SerpApi to web scrape from google product search. The API key has been taken out for obvious reasons. Every time I run the program, this error keeps coming up. How would I stop this from happening?
import json
from serpapi import GoogleSearch
params = {
"api_key": "api_key",
"engine": "google",
"q": "marvel",
"gl": "uk",
"hl": "en",
"tbm": "shop"
}
search = GoogleSearch(params)
results = search.get_dict()
for i in range(3):
for shopping_result in results['shopping_results']:
try:
title = shopping_result['title'] #Finds relating title
except:
title = "None"
try:
source = shopping_result['source'] #Finds relating title
except:
source = "None"
try:
price = shopping_result['price'] #Finds relating title
except:
price = "None"
print(title)
print(source)
print(price)
source https://stackoverflow.com/questions/71039757/unicodeencodeerror-ascii-codec-cant-encode-character-u2013-in-position-13

Comments
Post a Comment