Skip to content

Instantly share code, notes, and snippets.

@hkusu
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save hkusu/724448a76c29600f4ca8 to your computer and use it in GitHub Desktop.

Select an option

Save hkusu/724448a76c29600f4ca8 to your computer and use it in GitHub Desktop.
CasperJSでWEBサイトをスクレイピングしてみる ref: http://qiita.com/hkusu/items/e08226ca2e2e57d8ab97
elements = []
elements = @evaluate ->
items = document.querySelectorAll(".activities article .body a[href*=\"/items/\"]")
Array::map.call items, (e) ->
e.getAttribute('href');
elements_2 = []
i = 0
while i < elements.length
if elements[i].match(/^\/piyo/)
elements_2.push(elements[i])
i++
i = 0
while i < element.length
entry_days[i] = entry_days[i].replace(/[\n\r]/g,"")
entry_days[i] = entry_days[i].replace(/\ /g,"")
entry_days[i] = entry_days[i].replace(/<strong>.+?<\/strong>/g,"")
i++
casper = require("casper").create()
target_url = "http://qiita.com/organizations/yumemi"
# 対象のWEBページを開く
casper.start target_url, ->
urls = []
urls = @evaluate ->
items = document.querySelectorAll("a")
Array::map.call items, (e) ->
e.getAttribute('href')
# 出力
@echo(urls.join("\n"))
casper.run ->
@exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment