Я извлек название цитаты, следуя «учебнику» в документации по скрипированию. Проблема в том, что он дает мне два юникода в начале и в конце заголовка.Scrapy «Quotes Tutorial» - Unicode в извлеченном тексте
>>>quote = response.css("div.quote")[0]
>>> quote
<Selector xpath=u"descendant-or-self::div[@class and contains(concat(' ', normalize-space(@class), ' '), ' quote ')]" data=u'<div class="quote" itemscope itemtype="h'>
>>> title = quote.css("span.text::text").extract_first()
>>> title
u'\u201cThe world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.\u201d'
>>>
В документации извлеченный заголовок выглядит следующим образом:
>>>title
'"The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking."'
>>>
I`m не уверен, что я сделал неправильно здесь, просто следовал документацию. Есть ли что-то для настройки в файле конфигурации или как я могу это исправить? Ничего не упомянуто о декодировании/кодировании unicode.
Другой пример
продолжал я с документацией Scrapy, вот еще один пример:
Scrapy Shell Input:
>>> for quote in response.css("div.quote"):
... text = quote.css("span.text::text").extract_first()
... author = quote.css("small.author::text").extract_first()
... tags = quote.css("div.tags a.tag::text").extract()
... print(dict(text=text, author=author, tags=tags))
Выход сниппет:
{'text': u'\u201cTry not to become a man of success. Rather become a man of value.\u201d', 'tags': [u'humor', u'obvious', u'simile'], 'author': u'Albert Einstein'}
{'text': u'\u201cIt is better to be hated for what you are than to be loved for what you are not.\u201d', 'tags': [u'humor', u'obvious', u'simile'], 'author': u'Albert Einstein'}
{'text': u"\u201cI have not failed. I've just found 10,000 ways that won't work.\u201d", 'tags': [u'humor', u'obvious', u'simile'], 'author': u'Albert Einstein'}
{'text': u"\u201cA woman is like a tea bag; you never know how strong it is until it's in hot water.\u201d", 'tags': [u'humor', u'obvious', u'simile'], 'author': u'Albert Einstein'}
{'text': u'\u201cA day without sunshine is like, you know, night.\u201d', 'tags': [u'humor', u'obvious', u'simile'], 'author': u'Albert Einstein'}
Сайт, который я снял с:
Документация Scrapy (стр.20):
https://media.readthedocs.org/pdf/scrapy/1.2/scrapy.pdf
Система:
Macos Darwin Kernel Version 16.3.0: Чт 17 ноября 20:23:58 PST 2016; корень: XNU-3789.31.2 ~ 1/RELEASE_X86_64
virtualenv SCRAPY Python 2.7.10
Update
Я попробовал то же самое с новым virtualenv Python 3.5.2 с Python 3.5. 2 Наконец, я получаю правильные результаты, без проблемы с unicode, как в другой настройке.
Спасибо за ваш ответ;) – Luca