Skip to content

Instantly share code, notes, and snippets.

@vpatryshev
Last active December 26, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpatryshev/7076235 to your computer and use it in GitHub Desktop.
Save vpatryshev/7076235 to your computer and use it in GitHub Desktop.
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