Skip to content

Instantly share code, notes, and snippets.

@uehaj
Created October 10, 2010 16:19
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 uehaj/619360 to your computer and use it in GitHub Desktop.
Save uehaj/619360 to your computer and use it in GitHub Desktop.
// g100pon #37 GDKのコマンドラインビューア
@Grab('net.sourceforge.htmlunit:htmlunit:2.8')
import java.net.URL;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlHorizontalRule as HR;
proxyHost = null // set the proxy host name if you are in Firewall
proxyPort = 18080
if (proxyHost != null) {
c = new WebClient(BrowserVersion.FIREFOX_3, proxyHost , proxyPort);
}
else {
c = new WebClient(BrowserVersion.FIREFOX_3);
}
url = "http://groovy.codehaus.org/groovy-jdk/index-all.html"
allIndexPage = c.getPage(new URL(url));
if (args.size() == 0) {
println "Usage: groovy gdksearch.groovy kwd"
System.exit(0)
}
kwd = args[0]
anchors = allIndexPage.getByXPath("//a[starts-with(node(),'$kwd')]")
anchors.each{
println it.hrefAttribute
page = it.click()
desc = page.getByXPath("//a[starts-with(@name, '$kwd')]/following-sibling::*")
for (int i=1; i<desc.size() && !(desc[i] instanceof HR); i++) {
println desc[i].asText()
}
println ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment