static{
try{
File dir = new File(imgDir)
File[] imgFiles = dir.listFiles(new FilenameFilter(){
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".jpg")
}
})
通过httpclient来爬取网站内容,分析当前内容页中的图片‘规则’抓取一般都是模拟浏览器访问目标网页,通过返回的页面html代码进行分析自己需要的数据
查找规则,例如你爬取的网页 ,看到当前页面显示的图片格式如下<img src="http://www.baidu.com/img/20101025_user.png">
通过解析爬取的网页源代码(html)进行字符串的操作即可,现在有相应的第三方jar包可以帮你更快的完成这部分工作,例如htmlpaser,获取到对应的地址,然后进行保存或下载。
你可以搜索,java爬虫(httpclient)和htmlpaser做更多的了解。
String imageUrl="http://avatar.csdn.net/9/F/2/1_5iasp.jpg"BufferedImage image=getBufferedImage(imageUrl)
if (image!=null)
{
System.out.println("图片高度:"+image.getHeight())
System.out.println("图片宽度:"+image.getWidth())
}
else
{
System.out.println("图片不存在!")
}