使用Jsoup来获取字符串中img标签src的值

1、引入jsoup-1.9.2.jar包,下载地址http://www.open-open.com/jsoup/
使用Jsoup来获取字符串中img标签src的值_第1张图片
2、字符串值为:

Content=是芙蓉峰沃尔沃<img src="/fileimage/image/20160926/20160926092940_972.jpeg" alt="" />的的是非得失<img src="/fileimage/image/20160926/20160926092940_972.jpeg" alt="" />f是师范实得分<img src="/fileimage/image/20160923/20160923161211_378.jpeg" alt="" />w恶趣味​

3、java中代码:

String noticegroupContent = "是芙蓉峰沃尔沃20160926/20160926092940_972.jpeg" alt="" />的的是非得失20160926/20160926092940_972.jpeg" alt="" />f是师范实得分20160923/20160923161211_378.jpeg" alt="" />w恶趣味";
Document doc = Jsoup.parse(noticegroupContent);
Elements elements = doc.select("img[src]");//获取到的值为所有的
List list = new ArrayList();
int i = 0;
for (Element element : elements) {
    String src = element.attr("src");//获取到src的值
    String imgUrl = src.replace("/fileimage","E:/uploadlove/fileimage");//替换字符中所有的fileimage
    list.add(i, imgUrl);//放入list中
    i++;
}
System.out.println(list);

4、输入的list值为:

[E:/uploadlove/fileimage/image/20160926/20160926092940_972.jpeg, E:/uploadlove/fileimage/image/20160926/20160926092940_972.jpeg, E:/uploadlove/fileimage/image/20160923/20160923161211_378.jpeg]

你可能感兴趣的:(java)