4

私はこれに関する答えを探しましたが、答えが見つかりません。昨日述べたように、私はscrapyとpythonに慣れていないので、答えはそこにあるかもしれませんが、私は追いついていないのです。

私はうまく機能している私のクモを書きました。これが私のパイプラインです。

import sys
import MySQLdb
import hashlib
from scrapy.exceptions import DropItem
from scrapy.http import Request

class somepipeline(object):
    def __init__(self):
        self.conn = MySQLdb.connect(user='user', 'passwd', 'dbname', 'host', charset="utf8", use_unicode=True)
        self.cursor = self.conn.cursor()

    def process_item(self, item, spider):    
        try:
            self.cursor.execute("""INSERT INTO sometable (title, link, desc)  
                            VALUES (%s, %s)""", 
                           (item['title'].encode('utf-8'), 
                            item['link'].encode('utf-8'),
                            item['desc'].encode('utf-8'))

            self.conn.commit()
        except MySQLdb.Error, e:
            print "Error %d: %s" % (e.args[0], e.args[1])
        return item

これが私の設定です:

BOT_NAME = 'somebot'

SPIDER_MODULES = ['somespider.spiders']
NEWSPIDER_MODULE = 'somespider.spiders'
ITEM_PIPELINES = ['myproject.pipeline.somepipeline']

ただし、これを実行すると、次のようになります。パイプラインエラーという名前のモジュールがありません

同様の答えが見つかりましたが、それは画像クラス用であり、HTMLデータが必要です。

私は何が間違っているのですか?別のモジュールなどをダウンロードする必要がありますか?ヘルプに感謝します。近くにいる場合は、ひじをください。

4

3 に答える 3

2

Scrapy チュートリアルにはタイプミスがあります: 'pipelineS' でなければなりません

ITEM_PIPELINES = ['myproject.pipelines.somepipeline']
于 2014-02-09T20:43:17.853 に答える
1

「パイプライン」ファイルはありません。それは「パイプライン」でなければなりません。だから変える必要がある

ITEM_PIPELINES = ['myproject.pipeline.somepipeline']

ITEM_PIPELINES = ['myproject.pipelines.somepipeline']
于 2013-01-27T03:22:23.550 に答える