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


    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
    }

  • 相关阅读:
    RabbitMQ
    连接池,为什么要使用连接池?
    mac 安装arcanist
    感触
    UDP socket
    Servlet过滤器
    PL、SQL
    springmvc 文件上传实现(不是服务器的)
    注解spring
    excel工具类
  • 原文地址:https://www.cnblogs.com/lexus/p/2567719.html
Copyright © 2020-2023  润新知