I am trying to fetch recurring information (product names) from an e-commerce website. To do this, I use XPath. I have followed this tutorial to do so.
from lxml import html
import requests
page = requests.get("https://search.rakuten.co.jp/search/mall/-/565210/tg1000768/")
tree = html.fromstring(page.content)
urls = tree.xpath('//div[@class="image"]/a/img/@src')
titles = tree.xpath('//div[@class="content title"]/h2/a/text()')
print(len(titles))
print(titles)
The print(len(titles))
displays a correct number. However, the print(titles)
raises an error
print(titles)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-15: ordinal not in range(128)
What am I supposed to do ?