Skip to content

Instantly share code, notes, and snippets.

@amobiz
Created September 30, 2015 14:07
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 amobiz/087487e174646289afd1 to your computer and use it in GitHub Desktop.
Save amobiz/087487e174646289afd1 to your computer and use it in GitHub Desktop.
import java.io.FileWriter
import org.jdom.*
import org.jdom.input.*
import org.jdom.xpath.*
import org.jdom.output.*
import org.xml.sax.*
def builder = new SAXBuilder( "org.ccil.cowan.tagsoup.Parser" )
builder.setFeature( "http://xml.org/sax/features/namespace-prefixes", true )
builder.setFeature( "http://xml.org/sax/features/namespaces", false )
def xpath = XPath.newInstance( "//span[contains(@class,'titletext')]/text()" )
def is = new InputSource( "http://news.google.com.tw/" )
is.setEncoding( "UTF-8" )
def doc = builder.build( is )
new XMLOutputter().output( doc, new FileWriter( "output.html" ) )
def result = xpath.selectNodes( doc )
result.each { println it.value }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment