Skip to content

Instantly share code, notes, and snippets.

@latant
Last active March 10, 2020 14:50
Show Gist options
  • Save latant/69e5dc951db69b78577cfb700945ab90 to your computer and use it in GitHub Desktop.
Save latant/69e5dc951db69b78577cfb700945ab90 to your computer and use it in GitHub Desktop.
'Download your facebook information' generates html to view your messages, but the href attributes contain wrong directory names.It can be solved quickly by 'lowerCase-ing' the href attributes that start with 'messages' path segment.
import org.jsoup.Jsoup
import java.io.File
fun main(args: Array<String>) {
val (srcFile, targetFile) = args
val doc = Jsoup.parse(File(srcFile).readText())
doc.select("[href]").toList().forEach {
val pathSegments = it.attr("href").split("/").toMutableList()
if (pathSegments[0] == "messages") {
pathSegments[2] = pathSegments[2].toLowerCase()
it.attr("href", pathSegments.joinToString("/"))
}
}
File(targetFile).writeText(doc.toString())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment