Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created January 6, 2012 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hitode909/1570573 to your computer and use it in GitHub Desktop.
Save hitode909/1570573 to your computer and use it in GitHub Desktop.
auto shindanmaker for phantomjs
# phantomjs auto_shindanmaker.coffee
selectRandom = (list) ->
list[Math.floor(Math.random() * list.length)]
phantom.state = 0
page = new WebPage()
page.open 'http://shindanmaker.com/c/list', (status) ->
try
phantom.state++
if status != 'success'
console.log "failed at #{phantom.state}"
phantom.exit(1)
switch phantom.state
when 1
max = page.evaluate ->
link = document.querySelector('a.list_title')
href = link.href
match = href.match(/\d+/)
max = +match[0]
max
id = Math.floor(Math.random() * max)
page.open "http://shindanmaker.com/#{id}"
when 2
page.evaluate ->
document.querySelector('form#form')
input = document.querySelector('input.shindanuser')
input.value = 'hitode909' #XXX: http://code.google.com/p/phantomjs/issues/detail?id=132
form.submit()
when 3
res = page.evaluate ->
document.querySelector('textarea').value
console.log res
phantom.exit(0)
# window.setTimeout ->
# page.render 'a.png'
# phantom.exit()
# , 200
else
phantom.exit(1)
catch error
console.log "error at #{phantom.state}: #{error}"
phantom.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment