个性化阅读
专注于IT技术分析

Jsoup示例:打印URL的图像

点击下载

在此示例中, 我们将打印URL的全部图像。为此, 我们正在调用select()方法, 该方法传递“ img [src〜=(?i)\\。(png | jpe?g | gif)]”作为参数, 以便可以打印png, jpeg或gif图像。

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class JsoupPrintImages {
	 public static void main( String[] args ) throws IOException{
			Document doc = Jsoup.connect("http://www.srcmini02.com").get();
			Elements images = doc.select("img[src~=(?i)\\.(png|jpe?g|gif)]");
			for (Element image : images) {
				System.out.println("src : " + image.attr("src"));
				System.out.println("height : " + image.attr("height"));
				System.out.println("width : " + image.attr("width"));
				System.out.println("alt : " + image.attr("alt"));
			}
	 
}
}

输出:

src : http://www.srcmini02.com/images/social/r.png
height : 
width : 
alt : RSS Feed
src : http://www.srcmini02.com/images/social/m.png
height : 
width : 
alt : Subscribe to Get Email Alerts
src : http://www.srcmini02.com/images/social/f.png
height : 
width : 
alt : Facebook Page
src : http://www.srcmini02.com/images/social/g.png
height : 
width : 
alt : Google Page
src : http://www.srcmini02.com/images/social/t.png
height : 
width : 
alt : Twitter Page
src : images/logo/javahome.png
height : 
width : 
alt : Java tutorial
src : images/logo/javascripthome.png
height : 
width : 
alt : JavaScript tutorial
src : images/logo/sqlhome.png
height : 
width : 
alt : SQL tutorial
src : images/logo/androidhome.png
height : 
width : 
alt : Android tutorial
src : images/logo/clanguagehome.png
height : 
width : 
alt : C Language tutorial
src : images/logo/html-tutorial.png
height : 
width : 
alt : html tutorial
src : images/logo/pythonhome.png
height : 
width : 
alt : Python tutorial
src : images/logo/ajaxhome.png
height : 
width : 
alt : AJAX tutorial
src : images/logo/cloudhome.png
height : 
width : 
alt : Cloud tutorial
src : images/logo/javahome.png
height : 
width : 
alt : Core Java tutorial
src : images/logo/javahome.png
height : 
width : 
alt : Java Servlet tutorial
src : images/logo/jsphome.png
height : 
width : 
alt : Java JSP tutorial
src : images/logo/javahome.png
height : 
width : 
alt : EJB tutorial
src : images/logo/javahome.png
height : 
width : 
alt : JAXB tutorial
src : images/logo/strutshome.png
height : 
width : 
alt : Struts tutorial
src : images/logo/hibernatehome.png
height : 
width : 
alt : Hibernate tutorial
src : images/logo/springhome.png
height : 
width : 
alt : Spring tutorial
src : images/logo/javahome.png
height : 
width : 
alt : Java Mail tutorial
src : images/logo/javahome.png
height : 
width : 
alt : Java Design Pattern tutorial
src : images/logo/javahome.png
height : 
width : 
alt : JUnit tutorial
src : images/logo/strutshome.png
height : 
width : 
alt : Maven tutorial
src : images/logo/interviewhome.png
height : 
width : 
alt : Interview Questions
src : images/logo/projecthome.png
height : 
width : 
alt : Free Projects
src : images/logo/forumhome3.png
height : 
width : 
alt : Forum tutorial
src : images/logo/quizhome.png
height : 
width : 
alt : Online quiz
src : images/logo/javacompiler.png
height : 
width : 
alt : Online java compiler
src : images/sonoo9.jpg
height : 
width : 
alt : sonoo jaiswal
src : http://www.srcmini02.com/images/social/rss1.png
height : 
width : 
alt : RSS Feed
src : http://www.srcmini02.com/images/social/mail1.png
height : 
width : 
alt : Subscribe to Get Email Alerts
src : http://www.srcmini02.com/images/social/facebook1.jpg
height : 
width : 
alt : Facebook Page
src : http://www.srcmini02.com/images/social/google1.png
height : 
width : 
alt : Google Page
src : http://www.srcmini02.com/images/social/twitter1.png
height : 
width : 
alt : Twitter Page
src : http://www.srcmini02.com/images/social/blog.png
height : 
width : 
alt : Blog Page
src : http://images.dmca.com/Badges/dmca_protected_sml_120c.png
?ID=e8b533d5-7356-47f5-820b-72c890f03a4e
height : 
width : 
alt : DMCA.com
赞(0)
未经允许不得转载:srcmini » Jsoup示例:打印URL的图像

评论 抢沙发

评论前必须登录!