LoginSignup
1
2

More than 5 years have passed since last update.

Scrapyのサンプルプログラム

Last updated at Posted at 2017-03-05

まだまだ改善をしていきますが、自分メモ用的に残します。

サンプルプログラム

オフィシャルドキュメントを参考に、サンプルプログラムを作成した。
★店舗の一覧から店名と電話番号を取得する
(以前よく買い物していたフィットケアデポさんをサンプルとさせていただきました)

depo_spider.py
import scrapy


class DepoSpider(scrapy.Spider):
    name = "depo"
    start_urls = [
        'http://www.kamegaya.co.jp/cgi-bin/cl/public/index.cgi/kmg/search/index'
    ]

    def parse(self, response):
        for depo in response.css('div.result'):
            yield {
                'title': depo.css('h3 a::text').extract_first(),
                'tel' : depo.css('li.tel a::text').extract_first()
            }

プログラムの実行は以下。
(ググればすぐに見つかるけれど)

scrapy runspider depo_spider.py -o depo.json
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2