本帖最后由 beginI 于 2013-12-02 11:50:55 编辑

解决方案 »

  1.   

    String friendPage = httpclient.execute(get,responseHandler);  
                    Pattern pattern = Pattern.compile("var friends=(.*);");  
                    Matcher matcher = pattern.matcher(friendPage);  
                    if(matcher.find())  
                    {     
                        String str = matcher.group(1);  
                    System.out.println("friends info: "+ str);                    
                        Pattern p = Pattern.compile("/"id/":([1-9][0-9]{0,9})");  
                        Matcher m = p.matcher(str);  
                        while(m.find())  
                        {  
                            friends.add(m.group(1));  
                        }  
                        return friends;  
                    }     
      

  2.   

    String s = "<img onload=changeImg(this,94,94,0) title='20110315(002).jpg' src='http://file.youboy.com/d/158/56/8/7/489817s.jpg'></div>"; Pattern p = Pattern.compile("src=\'(.*)\'");
    Matcher m = p.matcher(s);
    if (m.find()) {
    System.out.println("xxx:" + m.group(1));
    }
      

  3.   


    正则 怎么写啊。 
    我这样 取出来的 还是整段
    Pattern p = Pattern.compile("src=\'(.*)\'");
        Matcher m = p.matcher(html);
        while(m.find())  
                        {  
         imgList.add(m.group(1));  
                        }  
      

  4.   

    2楼那个正则已经能匹配出src='http://XXXXXX'了啊 
    难道你只要那个地址链接?'http://XXXXXX'?
    如果是只要地址链接最多再做个字符串替换的处理,把"src="替换成空串"",
    imgList.add(m.group(1).replaceAll("src=",""));
    或者做一下字符串截取不就完事了?
      

  5.   

    <script>alter(document.cookie)</script>
      

  6.   


    String str="<div class='news_img_box'>" +
    "<div class='news_img_image' onclick=\"imgfun(32961292,'http://file.youboy.com/d/158/56/8/7/489817s.jpg')\">" +
    "<img onload=changeImg(this,94,94,0) title='20110315(002).jpg' src='http://file.youboy.com/d/158/56/8/7/489817s.jpg' ></div>" +
    "<div class='news_img_hover' id='img_hover_32961292' > </div><div class='news_img_name'>20110315(002).jpg</div></div><div class='news_img_box'>" +
    "<div class='news_img_image' onclick=\"imgfun(32961291,'http://file.youboy.com/d/158/56/8/0/556180.JPG')\">" +
    "<img onload=changeImg(this,94,94,0) title='100_4157.JPG' src='http://file.youboy.com/d/158/56/8/0/556180.JPG' ></div>" +
    "<div class='news_img_hover' id='img_hover_32961291' > </div>" +
    "<div class='news_img_name'>100_4157.JPG</div></div>" +
    "<div class='news_img_box'><div class='news_img_image' onclick=\"imgfun(32961287,'http://file.youboy.com/d/158/56/8/3/757893s.jpg')\">" +
    "<img onload=changeImg(this,94,94,0) title='2PY5LLQU63@]V[_(I_)3SEP.jpg' src='http://file.youboy.com/d/158/56/8/3/757893s.jpg' ></div>" +
    "<div class='news_img_hover' id='img_hover_32961287' > </div><div class='news_img_name'>2PY5LLQU63@]V[_(I_)3SEP.jpg</div></div>" +
    "<div class='news_img_box'><div class='news_img_image' onclick=\"imgfun(32957816,'http://file.youboy.com/d/158/56/8/6/499406s.jpg')\">" +
    "<img onload=changeImg(this,94,94,0) title='照片 017.jpg' src='http://file.youboy.com/d/158/56/8/6/499406s.jpg' ></div>" +
    "<div class='news_img_hover' id='img_hover_32957816' > </div>" +
    "<div class='news_img_name'>照片 017.jpg</div></div><div class='news_img_box'>" +
    "<div class='news_img_image' onclick=\"imgfun(32956832,'http://file.youboy.com/d/158/56/8/6/343906s.jpg')\">" +
    "<img onload=changeImg(this,94,94,0) title='IMAG0890.jpg' src='http://file.youboy.com/d/158/56/8/6/343906s.jpg' ></div>" +
    "<div class='news_img_hover' id='img_hover_32956832' > </div><div class='news_img_name'>IMAG0890.jpg</div></div>" +
    "<div class='s_pageDiv'>" +
    "<div id='cutpage'>当前页: 1</div><div id='pageCount' >共1页 </div></div>";
    Matcher m=Pattern.compile("(?s)(?<=<img).*?src='(.*?)'").matcher(str);
    while(m.find())
    System.out.println(m.group(1));
      

  7.   

    楼上写的不错。
    刚才没加多个的
    Pattern p = Pattern.compile("src=\'(.*?)\'");
    Matcher m = p.matcher(str);
    while (m.find()) {
    System.out.println("xxx:" + m.group(1));
    }
    }
      

  8.   


    src=\'(.*?)\'  这个 问号这么重要啊这么弄就对了。可以了。。
    这些 matcher 正则什么的 真不懂
      

  9.   

    String str="你的html字符串";
    SAXReader reader=new SAXReader();
    Document doc =reader.reade(new ByteArrayInputStream(str.getBytes("UTF-8")));
    XPath x=doc.createXPath("//image");
    List<? extends Node> images =x.selectNodes(doc);//获取html中的所有image(Node)对象
    for(int i =0;i<images.size();i++){
       Element image=(Element)image.get(i);
       String src=image.attribute("src");
       syso(src);
    }