您的位置:首页 > Web前端

use java style regular expression in groovy fetch and extractor info ,fucking urgly

2012-06-28 15:46 411 查看
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
System.properties.putAll( ["http.proxyHost":"10.10.224.97", "http.proxyPort":"80","http.proxyUserName":"admin", "http.proxyPassword":"admin888"] )

def url="http://detail.tmall.com/item.htm?id=8039043384&"
url="http://www.baidu.com"
html=url.toURL().text
//def matcher=( html=~ /<strong id="J_StrPrice"/ )
//println matcher

println html

String ResultString = null;
try {
Pattern regex = Pattern.compile("<strong id=\"J_StrPrice\" >([\\s\\S]*?)</strong>");
Matcher regexMatcher = regex.matcher(html);
if (regexMatcher.find()) {
ResultString = regexMatcher.group(1);
println(ResultString)
}
else
{
println("zzzz")
}
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: