Skip to content

Instantly share code, notes, and snippets.

@zhouji
Created April 13, 2012 16:04
Show Gist options
  • Save zhouji/2377961 to your computer and use it in GitHub Desktop.
Save zhouji/2377961 to your computer and use it in GitHub Desktop.
A script for download books from motie
// A script for download books from motie
import java.util.regex.Pattern
content= ""
def getIndex(indexURL){
(indexURL.toURL().text =~ /a href="(\/book\/[0-9]+_[0-9]+)" >第/ ).each{ a, b ->
getPage("http://www.motie.com/"+b)
}
}
def getPage(pageURL){
Pattern regex;
regex = Pattern.compile('<div class="hidden">(.*)</div>.*<div class="body-bg">', Pattern.DOTALL);
(pageURL.toURL().text =~ regex).each{ a,b ->
content += b
}
}
getIndex('http://www.motie.com/book/6723/chapter')
f = new File("book.txt")
f.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment