Skip to content

Instantly share code, notes, and snippets.

@hitsujixgit
Created January 12, 2015 04:25
Show Gist options
  • Save hitsujixgit/a3077812d3b4411d9053 to your computer and use it in GitHub Desktop.
Save hitsujixgit/a3077812d3b4411d9053 to your computer and use it in GitHub Desktop.
CasperJS crawler sample.
###
* ローソンの店舗情報を1件スクレイピングする
###
target_url = "http://store.lawson.co.jp"
casper = require('casper').create()
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36')
casper.start target_url
# 都道府県リスト表示
casper.then ->
@click('p.listSearch a')
# 最初の都道府県(北海道)をクリック
casper.waitForSelector "ul.mapOverLayLists li:nth-child(1) a", ->
@echo(@fetchText('ul.mapOverLayLists li:nth-child(1) a'))
@click('ul.mapOverLayLists li:nth-child(1) a')
# 最初の市区町村(札幌市中央区)をクリック
casper.wait(500).waitForSelector "ul.mapOverLayLists li:nth-child(1) a", ->
@echo(@fetchText('ul.mapOverLayLists li:nth-child(1) a'))
@click('ul.mapOverLayLists li:nth-child(1) a')
# 店舗をクリック
casper.wait(500).waitForSelector '#mapOverLay table a', ->
@echo(@fetchText('#mapOverLay table a'))
@click('#mapOverLay table a')
# 結果確認
casper.wait(500).waitForSelector '#pr_address', ->
@capture('hoge.png')
@echo(@fetchText('#pr_address'))
casper.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment