私はこの文書に従って、scrapyを使用して画像をダウンロードします。 http://doc.scrapy.org/en/latest/topics/images.htmlscrapy imagepipline:簡単な例が作成されました。実行する/テストするコマンドは何ですか?
具体的には、私はこのtest.pyを持っているでしょう:
from scrapy.contrib.pipeline.images import ImagesPipeline
from scrapy.exceptions import DropItem
from scrapy.http import Request
from My.items import ImageItem
item = ImageItem()
item['image_urls'] = ['http://url/123.jpg']
class MySpider(ImagesPipeline):
def get_media_requests(self, item, info):
for image_url in item['image_urls']:
yield Request(image_url)
def item_completed(self, results, item, info):
image_paths = [x['path'] for ok, x in results if ok]
if not image_paths:
raise DropItem("Item contains no images")
item['image_paths'] = image_paths
return item
私の質問です:コマンドラインが何であるかを私はイメージがダウンロードされているかどうかを確認するために、このtest.pyをテストするために実行する必要があります。
さらに詳しい情報: 私はコマンド "scrapy crawl project_name"を知っていますが、プロジェクトを作成せずにこのtest.pyをテストすることをお勧めします。
また、「scrapy runspider test.py」に出てきますが、動作しません。エラー:MySpiderが見つかりません。
スパイダーを1つのスクリプトから実行する場合は、次のスニペットを実行してください:[サイトをクロールするための自己完結型スクリプト](http://snippets.scrapy.org/snippets/7/) – reclosedev
@SjaakTrekhaak、 'Scrapy 0.14.1'のスニペットをテストしました。 – reclosedev
@reclosedevあなたは正しいです。私はメインプロセスの代わりに子プロセスで問題を使用していました(信号はメインスレッドでのみ使用できます)。この疑問を混乱させました。 –