Last active
December 26, 2015 02:09
-
-
Save vpatryshev/7076235 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
def downloadPDF(url: String): Result[(File, String)] = { | |
loadPage(url) andThen | |
waitForSelector("div.textLayer") andThen | |
runJS("return extractPdfContent()") andThen { | |
Thread.sleep(2000) // give browser a chance | |
val extracted = runJS("return intBuf2hex(extractedPdf)") map (_.toString) | |
val pdf = extracted flatMap | |
(_.decodeHex #> File.createTempFile("download", ".pdf")) | |
val html = runJS("return _$('div.textLayer').innerHTML") map (_.toString) | |
pdf <*> html | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment