Created
October 10, 2010 16:19
-
-
Save uehaj/619360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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