groovy正则提取完整版本

import java.util.regex.*
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" >([\s\S]*?)<\/strong>/ )
if (matcher.find())
{
    def temp_price= matcher[0][1]
    if(temp_price.isNumber())
    {
       //println Double.parseDouble(temp_price)
       temp_price=temp_price as double
       println temp_price.toString()
    }
}
else
{
    println "未匹配"
}

你可能感兴趣的:(groovy)