Python utf-8 encoding question. Among the crawled data, the data contained in the list field was encoded ('utf-8')
['\xe5\xb0\x8f\xe5\xb7\x9d\xe9\x9f\xb3\xe5\xad\x90']
When you output the dictionary value list itself as shown in , it is output as hex bytes.
But
a[0].encode('utf-8')
If you encode only the first element in , it will be printed normally in Japanese that I crawled. How do I get all the elements in the list printed in Japanese that have been crawled?
python encoding
I solved it. Python outputs hex data when it outputs the encoded list itself. So I converted it into a string as a list join and printed it out, and I got the desired result. The code I used is as follows.
name = sel.xpath('//*[@id="performer"]/a/text()').extract()
namejoin = [n.encode('utf-8') for n in name]
item['name'] = " , ".join(namejoin)
print item['name']
It's hard to do this and that because I'm a very old coding person TT
© 2024 OneMinuteCode. All rights reserved.