Last active
August 29, 2015 14:04
-
-
Save ssig33/67ce46ae579d0d670495 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## coffee -csb | |
page = require('webpage').create() | |
fs = require('fs') | |
page.viewportSize = {width:1280,height:1024} | |
page.settings.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" | |
console.log "DRIVERS START YOUR ENGINE!!" | |
signin = -> | |
console.log 'SIGN IN PAGE LOADED' | |
setTimeout(-> | |
page.render 'signin.png' | |
page.onLoadFinished = -> | |
page.onLoadFinished = -> console.log 'finish' | |
console.log 'sign in' | |
setTimeout(-> | |
page.render('home.png') | |
title = page.evaluate -> jQuery('.headerTitle').get(0).innerText | |
author = page.evaluate -> jQuery('tr > td:nth-child(3)').get(0).innerText | |
console.log title | |
try | |
list = JSON.parse(fs.read('list.json')) | |
catch e | |
list = [] | |
if list.indexOf(title) > -1 | |
phantom.exit() | |
page.evaluate -> jQuery('#actionSelect1').click() | |
console.log 'click 1' | |
setTimeout(-> | |
page.render('1.png') | |
if page.evaluate(-> jQuery('#downloadLink_1').get(0)) | |
page.evaluate -> jQuery('#downloadLink_1').click() | |
console.log 'click 2' | |
setTimeout(-> | |
page.onUnsupportedContentReceived = (response)-> | |
console.log response.id | |
console.log response | |
page.saveUnsupportedContent("(Kindle)[#{author}]#{title}.azw3", response.id) | |
try | |
list = JSON.parse(fs.read('list.json')) | |
catch e | |
list = [] | |
list.push title | |
fs.write('list.json', JSON.stringify(list), 'w') | |
phantom.exit() | |
page.render '2.png' | |
page.evaluate -> jQuery('#download_1 > form > div > table > tbody > tr:nth-child(2) > td:nth-child(1) > input').attr('onclick')() | |
console.log 'start download' | |
,1000) | |
else | |
phantom.exit() | |
,1000) | |
,1500) | |
page.evaluate -> | |
document.querySelector('#ap_email').value = '' | |
document.querySelector('#ap_password').value = '' | |
document.querySelector('#ap_signin_form').submit() | |
,1500) | |
page.open('https://www.amazon.co.jp/gp/digital/fiona/manage?ie=UTF8&ref_=gno_yam_myk&signInRedirect=1&#Books', (status)-> signin()) | |
# vim: set ft=coffee : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment