http://www.ip138.com/ips.asp?ip=14.147.43.45
我要抓取这个网站的“本站主数据:广东省广州市 电信”地址如何抓取?
注:“本站主数据:广东省广州市 电信”地址是随机的,也许换了个ip就变成了"本站主数据:上海市 电信(金山区)"
无论根据什么ip 我只要获取“本站主数据:xxxx”的地址就行。
谢谢了。

解决方案 »

  1.   

    用jsoup框架,强烈摧荐,我用过非常的好用!
      

  2.   


    public static void main(String[] args) {
     String ip="14.147.43.45";
     String url = "http://www.ip138.com/ips.asp";
     HttpClient client = new HttpClient();
     PostMethod method = new PostMethod(url);
     method.setParameter("ip", ip);
      method.getParams().setContentCharset("GBK");
     try {
    client.executeMethod(method);
    int statecode = method.getStatusCode();
                if (statecode == HttpStatus.SC_OK) {
                  String temp=method.getResponseBodyAsString();
              String rex = "<li>.*</li>";
              Pattern p = Pattern.compile(rex);
              Matcher m = p.matcher(temp);
                    if(m.find()){
                     System.out.println(m.group());
                    }            }
    } catch (HttpException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
        }
    }
      

  3.   

    java正则  Pattern  Matcher
      

  4.   

    我想问一下,只要获取“本站主数据:广东省广州市 电信”正则怎么改呢?
    你这个正则是获取“<li>本站主数据:广东省广州市 电信</li><li>参考数据一:广东省 电信</li>”吧