Created
January 6, 2012 13:23
-
-
Save hitode909/1570573 to your computer and use it in GitHub Desktop.
auto shindanmaker for phantomjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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