Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Groovy(Geb)による、期間限定で全ページが無料公開されている「写真家65人のレンズテクニック」の画像を保存するスクリプトです。 http://dc.watch.impress.co.jp/docs/news/20160225_745061.html
@Grab('org.gebish:geb-core')
@Grab('org.seleniumhq.selenium:selenium-firefox-driver')
@GrabExclude('org.codehaus.groovy:groovy-all')
import geb.Browser
Browser.drive {
go 'http://impress.tameshiyo.me/9784844337966'
sleep(2000)
// get encoded iamges in data URI
def list = []
// 89 pages
(0..88).each { page ->
list << $('div.page_pnl', 'data-page-prefix': "${page % 2 * 2}")?.children()[0].@src
list << $('div.page_pnl', 'data-page-prefix': "${page % 2 * 2 + 1}")?.children()[0].@src
$('div#book_frame').click()
sleep(1000)
}
// decode & save iamges
list.eachWithIndex { url, index ->
if(url.startsWith('data:') && url.split(',').size() == 2) {
def data = url.split(',')[1]
new File("page${index}.jpg").bytes = Base64.getDecoder().decode(data)
}
}
}
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.