我按照scrapy文档中的“tutorial”提取了引用的标题。问题是,它在标题的开头和结尾处给了我两个unicode。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."'
>>>
我真的不知道我做错了什么在这里,只是跟着的文档。有没有在配置文件中设置的东西,或者我该如何解决这个问题? 关于解码/编码unicode没有提及。
其他实施例
我接着与scrapy文档,这里是一个例子:
Scrapy壳牌输入:
>>> 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达尔文内核版本16.3.0:星期四11月17日20时23分58秒PST 2016年根:XNU-3789.31.2〜1/RELEASE_X86_64
的virtualenv scrapy 的Python 2.7.10
更新
我试图在同一用新的virtualenv的Python 3.5.2 使用Python 3.5。 2我终于得到了正确的结果,没有像其他设置中的unicode问题。
谢谢您的回答;) – Luca