Jsoup官网地址:http://jsoup.org/
1. 解析单个input元素
String html = "<p><input align="top" src="/项目名/userfiles/image/yiyiren.jpg" width="60%" type="image" longdesc="undefined" /></p>";
Document doc = Jsoup.parse(html);
Element inputTag = doc.select("input").first();
String imgUrl = inputTag.attr("src");
2. 解析多个input元素
String html = "<p><input src="/项目名/userfiles/image/QQ图片20130618085610.jpg" width="200" height="99" type="image" longdesc="undefined" /><strong>名称</strong>:薏苡仁<br /><input align="top" src="/项目名/userfiles/image/yiyiren.jpg" width="60%" type="image" longdesc="undefined" /><br /></p>";
Document doc = Jsoup.parse(html);
Elements elements = doc.select("input");
for(Element inputTag : elements)
{
String imgUrl = inputTag.attr("src");
System.out.println("imgUrl=====" + imgUrl);
}
利用正则表达式获取HTML内容中的图片标签:
1. <img[^>]+src\s*=\s*['"]([^'"]+)['"][^>]*>
2. <input[^>]+src\s*=\s*['"]([^'"]+)['"][^>]*>