Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.