私は、治療のドキュメントの "チュートリアル"の後に引用符のタイトルを抽出しました。問題は、タイトルの最初と最後に2つのユニコードがあることです。ドキュメントでScrapy "引用チュートリアル" - 抽出されたテキストの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私はここで間違って何をしたかわからない、ただのドキュメントを追いました。設定ファイルに何か設定する方法がありますか、これをどのように修正できますか? ユニコードのデコード/エンコードについて何も言及されていません。例
その他
私はここで、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'}
サイトiを掻き取った:
ドキュメントScrapy(P.20):
https://media.readthedocs.org/pdf/scrapy/1.2/scrapy.pdf
システム:
MacOSのダーウィンカーネルバージョン16.3.0:木11月17日午後8時23分58秒PST 2016;ルート:XNU-3789.31.2〜1/RELEASE_X86_64
virtualenvののscrapy のPython 2.7.10
更新
は、私は、Python 3.5で新たにvirtualenvのののPython 3.5.2 と同じことを試してみました。 2私は最終的に、他の設定のようなユニコードの問題なしに正しい結果を得ます。
ありがとうございます;) – Luca