0

My Item class is as follows:

class SkeletonItem(scrapy.Item):
    name = scrapy.Field()

In the parse() function of spider class, the logic is as follows:

soup = BeautifulSoup(response.body, 'html.parser')
si = SkeletonItem()
si['name'] = li.find("div", {"class": "info-panel"}).find("h2").text.encode('utf-8')
print si['name'] # str'中文'
print si         # str'\u1234\u5678'
retirm si

As we can see, it outputs well when printing si['name'], whereas it merely shows unicode when printing si as a whole. The above phenomenon leads to the problem that when I write si to file, it only shows unicode in the file.

Could anyone give me some idea? Great thanks.

1 Answer 1

1

I think you will find your answer here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.