从网页获取图片

从中央气象台获取卫星云图的例子,代码如下:

url:地址

package com.jointsky.jointframe.test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 从中国气象台网站获取卫星云图的例子
 * @author Administrator
 *
 */
public class GetSatelliteCloudImageTest {
        //格式化时间
        private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        private static SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
        private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        private static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy/MM/dd/");
        private static SimpleDateFormat sdf4 = new SimpleDateFormat("yyyyMMdd");
        private static SimpleDateFormat sdf5 = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");

        /**
         * 主函数
         * @param args
         */
        public static void main(String[] args) {

        //每日卫星云图第一张数据的时间是"03:59:59",但是接近整点的时候才会发布;最后一张图片是23:45的,放在00:00:00之后到00:10:00之间取数据
        //不取数据的开始时间(时间在每天的00:10:00到03:59:59秒之间不取数据)
        String beginTime = " 00:10:00";
        //不去数据的结束时间
        String endTime = " 03:59:59";

        Date date = new Date();
        //当前时间(无时分秒)
        String currentTime1 = sdf1.format(date);
        Date begin = new Date();
        Date end =  new Date();
        Date current =  new Date();
        String b = currentTime1+beginTime;
        String e = currentTime1+endTime;
        try {
            begin = sdf.parse(b);
            end = sdf.parse(e);
            current = date;
            //current = sdf.parse(currentTime1+" "+currentTime2);
        } catch (ParseException e1) {
            e1.printStackTrace();
        }
        //before方法:begin时间在当前时间current返回true
        if (begin.before(current)&&current.before(end)) {
            return;
        }else {
            try {
                String url = getImageUrl(date);
                String filename = getImageName(date,getTimeCode(date));
                Map<String, Object> map = download(url, filename);
                //图片名称
                String imageName = (String) map.get("filename");
                //预报时间
                String forecastTime = (String) map.get("forecastTime");
                //图片路径
                String imagePath = (String) map.get("imagePath");
                System.out.println("图片名称:"+imageName+";预报时间:"+forecastTime+";路径:"+imagePath);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }

    /**
     * 获取卫星云图的url地址
     * @return
     * @throws Exception
     */
    public static String getImageUrl(Date date) throws Exception {
        //"http://image.nmc.cn/product/2017/03/24/WXCL/medium/SEVP_NSMC_WXCL_ASC_E99_ACHN_LNO_PY_20170324071500000.JPG"
        String url = "http://image.nmc.cn/product/";

        //图片名称
        String imageName = "SEVP_NSMC_WXCL_ASC_E99_ACHN_LNO_PY_";
        //时间编码
        String timeCode = getTimeCode(date);

        Integer code = Integer.parseInt(timeCode);

        //url前部出现的时间
        String time = sdf3.format(date);
        String name_time = "";

        if (code>=1945) {
            //前一天
            Date timex = new Date(date.getTime() - 86400000);
            name_time = sdf4.format(timex);
        }else {
            name_time = sdf4.format(date);
        }

        //图片格式
        String imgLayout = "00000.JPG";
        url = url + time + "WXCL/medium/" + imageName + name_time + timeCode + imgLayout;
        return url;
    }

    /**
     * 获取预报时间对应的时间代码
     * @param date
     * @return
     * @throws Exception
     */
    public static String getTimeCode(Date date) throws Exception {
        //当前日期
        String currentDate = sdf1.format(date);
        if (sdf.parse(currentDate+" 03:59:00").before(date)&&(sdf.parse(currentDate+" 04:30:00")).after(date)||(sdf.parse(currentDate+" 04:30:00")).equals(date)) {
            return "1945";
        }else if (sdf.parse(currentDate+" 04:30:00").before(date)&&(sdf.parse(currentDate+" 04:59:59")).after(date)||(sdf.parse(currentDate+" 04:59:59")).equals(date)) {
            return "2015";
        }else if (sdf.parse(currentDate+" 04:59:59").before(date)&&(sdf.parse(currentDate+" 05:30:00")).after(date)||(sdf.parse(currentDate+" 05:30:00")).equals(date)) {
            return "2045";
        }else if (sdf.parse(currentDate+" 05:30:00").before(date)&&(sdf.parse(currentDate+" 05:59:59")).after(date)||(sdf.parse(currentDate+" 05:59:59")).equals(date)) {
            return "2115";
        }else if (sdf.parse(currentDate+" 05:59:59").before(date)&&(sdf.parse(currentDate+" 06:30:00")).after(date)||(sdf.parse(currentDate+" 06:30:00")).equals(date)) {
            return "2145";
        }else if (sdf.parse(currentDate+" 06:30:00").before(date)&&(sdf.parse(currentDate+" 06:59:59")).after(date)||(sdf.parse(currentDate+" 06:59:59")).equals(date)) {
            return "2215";
        }else if (sdf.parse(currentDate+" 06:59:59").before(date)&&(sdf.parse(currentDate+" 07:30:00")).after(date)||(sdf.parse(currentDate+" 07:30:00")).equals(date)) {
            return "2245";
        }else if (sdf.parse(currentDate+" 07:30:00").before(date)&&(sdf.parse(currentDate+" 07:59:59")).after(date)||(sdf.parse(currentDate+" 07:59:59")).equals(date)) {
            return "2315";
        }else if (sdf.parse(currentDate+" 07:59:59").before(date)&&(sdf.parse(currentDate+" 08:30:00")).after(date)||(sdf.parse(currentDate+" 08:30:00")).equals(date)) {
            return "2345";
        }else if (sdf.parse(currentDate+" 08:30:00").before(date)&&(sdf.parse(currentDate+" 08:30:00")).after(date)||(sdf.parse(currentDate+" 08:59:59")).equals(date)) {
            return "0015";
        }else if (sdf.parse(currentDate+" 08:59:59").before(date)&&(sdf.parse(currentDate+" 09:30:00")).after(date)||(sdf.parse(currentDate+" 09:30:00")).equals(date)) {
            return "0045";
        }else if (sdf.parse(currentDate+" 09:30:00").before(date)&&(sdf.parse(currentDate+" 09:59:59")).after(date)||(sdf.parse(currentDate+" 09:59:59")).equals(date)) {
            return "0115";
        }else if (sdf.parse(currentDate+" 09:59:59").before(date)&&(sdf.parse(currentDate+" 10:30:00")).after(date)||(sdf.parse(currentDate+" 10:30:00")).equals(date)) {
            return "0145";
        }else if (sdf.parse(currentDate+" 10:30:00").before(date)&&(sdf.parse(currentDate+" 10:59:59")).after(date)||(sdf.parse(currentDate+" 10:59:59")).equals(date)) {
            return "0215";
        }else if (sdf.parse(currentDate+" 10:59:59").before(date)&&(sdf.parse(currentDate+" 11:30:00")).after(date)||(sdf.parse(currentDate+" 11:30:00")).equals(date)) {
            return "0245";
        }else if (sdf.parse(currentDate+" 11:30:00").before(date)&&(sdf.parse(currentDate+" 11:59:59")).after(date)||(sdf.parse(currentDate+" 11:59:59")).equals(date)) {
            return "0315";
        }else if (sdf.parse(currentDate+" 11:59:59").before(date)&&(sdf.parse(currentDate+" 12:30:00")).after(date)||(sdf.parse(currentDate+" 12:30:00")).equals(date)) {
            return "0345";
        }else if (sdf.parse(currentDate+" 12:30:00").before(date)&&(sdf.parse(currentDate+" 12:59:59")).after(date)||(sdf.parse(currentDate+" 12:59:59")).equals(date)) {
            return "0415";
        }else if (sdf.parse(currentDate+" 12:59:59").before(date)&&(sdf.parse(currentDate+" 13:30:00")).after(date)||(sdf.parse(currentDate+" 13:30:00")).equals(date)) {
            return "0445";
        }else if (sdf.parse(currentDate+" 13:30:00").before(date)&&(sdf.parse(currentDate+" 13:59:59")).after(date)||(sdf.parse(currentDate+" 13:59:59")).equals(date)) {
            return "0515";
        }else if (sdf.parse(currentDate+" 13:59:59").before(date)&&(sdf.parse(currentDate+" 14:30:00")).after(date)||(sdf.parse(currentDate+" 14:30:00")).equals(date)) {
            return "0545";
        }else if (sdf.parse(currentDate+" 14:30:00").before(date)&&(sdf.parse(currentDate+" 14:59:59")).after(date)||(sdf.parse(currentDate+" 14:59:59")).equals(date)) {
            return "0615";
        }else if (sdf.parse(currentDate+" 14:59:59").before(date)&&(sdf.parse(currentDate+" 15:30:00")).after(date)||(sdf.parse(currentDate+" 15:30:00")).equals(date)) {
            return "0645";
        }else if (sdf.parse(currentDate+" 15:30:00").before(date)&&(sdf.parse(currentDate+" 15:59:59")).after(date)||(sdf.parse(currentDate+" 15:59:59")).equals(date)) {
            return "0715";
        }else if (sdf.parse(currentDate+" 15:59:59").before(date)&&(sdf.parse(currentDate+" 16:30:00")).after(date)||(sdf.parse(currentDate+" 16:30:00")).equals(date)) {
            return "0745";
        }else if (sdf.parse(currentDate+" 16:30:00").before(date)&&(sdf.parse(currentDate+" 16:59:59")).after(date)||(sdf.parse(currentDate+" 16:59:59")).equals(date)) {
            return "0815";
        }else if (sdf.parse(currentDate+" 16:59:59").before(date)&&(sdf.parse(currentDate+" 17:30:00")).after(date)||(sdf.parse(currentDate+" 17:30:00")).equals(date)) {
            return "0845";
        }else if (sdf.parse(currentDate+" 17:30:00").before(date)&&(sdf.parse(currentDate+" 17:59:59")).after(date)||(sdf.parse(currentDate+" 17:59:59")).equals(date)) {
            return "0915";
        }else if (sdf.parse(currentDate+" 17:59:59").before(date)&&(sdf.parse(currentDate+" 18:30:00")).after(date)||(sdf.parse(currentDate+" 18:30:00")).equals(date)) {
            return "0945";
        }else if (sdf.parse(currentDate+" 18:30:00").before(date)&&(sdf.parse(currentDate+" 18:59:59")).after(date)||(sdf.parse(currentDate+" 18:59:59")).equals(date)) {
            return "1015";
        }else if (sdf.parse(currentDate+" 18:59:59").before(date)&&(sdf.parse(currentDate+" 19:30:00")).after(date)||(sdf.parse(currentDate+" 19:30:00")).equals(date)) {
            return "1045";
        }else if (sdf.parse(currentDate+" 19:30:00").before(date)&&(sdf.parse(currentDate+" 19:59:59")).after(date)||(sdf.parse(currentDate+" 19:59:59")).equals(date)) {
            return "1115";
        }else if (sdf.parse(currentDate+" 19:59:59").before(date)&&(sdf.parse(currentDate+" 20:30:00")).after(date)||(sdf.parse(currentDate+" 20:30:00")).equals(date)) {
            return "1145";
        }else if (sdf.parse(currentDate+" 20:30:00").before(date)&&(sdf.parse(currentDate+" 20:59:59")).after(date)||(sdf.parse(currentDate+" 20:59:59")).equals(date)) {
            return "1215";
        }else if (sdf.parse(currentDate+" 20:59:59").before(date)&&(sdf.parse(currentDate+" 21:30:00")).after(date)||(sdf.parse(currentDate+" 21:30:00")).equals(date)) {
            return "1245";
        }else if (sdf.parse(currentDate+" 21:30:00").before(date)&&(sdf.parse(currentDate+" 21:59:59")).after(date)||(sdf.parse(currentDate+" 21:59:59")).equals(date)) {
            return "1315";
        }else if (sdf.parse(currentDate+" 21:59:59").before(date)&&(sdf.parse(currentDate+" 22:30:00")).after(date)||(sdf.parse(currentDate+" 22:30:00")).equals(date)) {
            return "1345";
        }else if (sdf.parse(currentDate+" 22:30:00").before(date)&&(sdf.parse(currentDate+" 22:59:59")).after(date)||(sdf.parse(currentDate+" 22:59:59")).equals(date)) {
            return "1415";
        }else if (sdf.parse(currentDate+" 22:59:59").before(date)&&(sdf.parse(currentDate+" 23:30:00")).after(date)||(sdf.parse(currentDate+" 23:30:00")).equals(date)) {
            return "1445";
        }else if (sdf.parse(currentDate+" 23:30:00").before(date)&&(sdf.parse(currentDate+" 22:59:59")).after(date)||(sdf.parse(currentDate+" 23:59:59")).equals(date)) {
            return "1515";
        }else if (sdf.parse(currentDate+" 23:59:59").before(date)&&(sdf.parse(currentDate+" 23:59:59")).after(date)||(sdf.parse(currentDate+" 23:59:59")).equals(date)) {
            return "1545";
        }else if ((sdf.parse(currentDate+" 00:00:00").before(date)||sdf.parse(currentDate+" 00:00:00").equals(date))&&(sdf.parse(currentDate+" 03:59:59").after(date))||sdf.parse(currentDate+" 03:59:59").equals(date)) {
            return "1545";
        }

        return null;
    }

    /**
     * 根据时间和时间代码获取到新命名的卫星云图文件名
     * @param date
     * @param timeCode
     * @return
     * @throws Exception
     */
    public static String getImageName(Date date,String timeCode) throws Exception {
        String time = sdf1.format(date);
        if ("1945".equals(timeCode)) {
            return time+"-03-45-00.JPG";
        }else if ("2015".equals(timeCode)) {
            return time+"-04-15-00.JPG";
        }else if ("2045".equals(timeCode)) {
            return time+"-04-45-00.JPG";
        }else if ("2115".equals(timeCode)) {
            return time+"-05-15-00.JPG";
        }else if ("2145".equals(timeCode)) {
            return time+"-05-45-00.JPG";
        }else if ("2215".equals(timeCode)) {
            return time+"-06-15-00.JPG";
        }else if ("2245".equals(timeCode)) {
            return time+"-06-45-00.JPG";
        }else if ("2315".equals(timeCode)) {
            return time+"-07-15-00.JPG";
        }else if ("2345".equals(timeCode)) {
            return time+"-07-45-00.JPG";
        }else if ("0015".equals(timeCode)) {
            return time+"-08-15-00.JPG";
        }else if ("0045".equals(timeCode)) {
            return time+"-08-45-00.JPG";
        }else if ("0115".equals(timeCode)) {
            return time+"-09-15-00.JPG";
        }else if ("0145".equals(timeCode)) {
            return time+"-09-45-00.JPG";
        }else if ("0215".equals(timeCode)) {
            return time+"-10-15-00.JPG";
        }else if ("0245".equals(timeCode)) {
            return time+"-10-45-00.JPG";
        }else if ("0315".equals(timeCode)) {
            return time+"-11-15-00.JPG";
        }else if ("0345".equals(timeCode)) {
            return time+"-11-45-00.JPG";
        }else if ("0415".equals(timeCode)) {
            return time+"-12-15-00.JPG";
        }else if ("0445".equals(timeCode)) {
            return time+"-12-45-00.JPG";
        }else if ("0515".equals(timeCode)) {
            return time+"-13-15-00.JPG";
        }else if ("0545".equals(timeCode)) {
            return time+"-13-45-00.JPG";
        }else if ("0615".equals(timeCode)) {
            return time+"-14-15-00.JPG";
        }else if ("0645".equals(timeCode)) {
            return time+"-14-45-00.JPG";
        }else if ("0715".equals(timeCode)) {
            return time+"-15-15-00.JPG";
        }else if ("0745".equals(timeCode)) {
            return time+"-15-45-00.JPG";
        }else if ("0815".equals(timeCode)) {
            return time+"-16-15-00.JPG";
        }else if ("0845".equals(timeCode)) {
            return time+"-16-45-00.JPG";
        }else if ("0915".equals(timeCode)) {
            return time+"-17-15-00.JPG";
        }else if ("0945".equals(timeCode)) {
            return time+"-17-45-00.JPG";
        }else if ("1015".equals(timeCode)) {
            return time+"-18-15-00.JPG";
        }else if ("1045".equals(timeCode)) {
            return time+"-18-45-00.JPG";
        }else if ("1115".equals(timeCode)) {
            return time+"-19-15-00.JPG";
        }else if ("1145".equals(timeCode)) {
            return time+"-19-45-00.JPG";
        }else if ("1215".equals(timeCode)) {
            return time+"-20-15-00.JPG";
        }else if ("1245".equals(timeCode)) {
            return time+"-20-45-00.JPG";
        }else if ("1315".equals(timeCode)) {
            return time+"-21-15-00.JPG";
        }else if ("1345".equals(timeCode)) {
            return time+"-21-45-00.JPG";
        }else if ("1415".equals(timeCode)) {
            return time+"-22-15-00.JPG";
        }else if ("1445".equals(timeCode)) {
            return time+"-22-45-00.JPG";
        }else if ("1515".equals(timeCode)) {
            return time+"-23-15-00.JPG";
        }else if ("1545".equals(timeCode)) {
            return time+"-23-45-00.JPG";
        }
        return null;
    }

    /**
       * 下载文件到本地
       * @param urlString 被下载的文件地址
       * @param filename 本地文件名
       * @throws Exception 各种异常
       */
    public static Map<String, Object> download(String urlString, String filename) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        String path = "";
        Date time = sdf5.parse(filename);
        String forecastTime = sdf.format(time);
        String imagePath = "D:/Jointsky/JointFrame/satelliteCloudImage/";
        String[] filenames = filename.split("\\.");
        String[] strs = filenames[0].split("-");
        for (int i = 0; i < strs.length; i++) {
            imagePath = imagePath + strs[i]+"/";
        }

        path = imagePath;
        imagePath = imagePath + filename;
        // 构造URL
        URL url = new URL(urlString);
        // 打开连接
        URLConnection con = url.openConnection();
        // 输入流
        InputStream is = con.getInputStream();
        // 1K的数据缓冲
        byte[] bs = new byte[1024];
        // 读取到的数据长度
        int len;
        //判断如果文件夹存在则保存,不存在则创建
        File file = new File(path);
        if (!file.exists()) {
            if (!file.isDirectory()) {
                file.mkdirs();
            }
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        // 输出的文件流
        OutputStream os = new FileOutputStream(imagePath);
        // 开始读取
        while ((len = is.read(bs)) != -1) {
          os.write(bs, 0, len);
        }
        // 完毕,关闭所有链接
        os.close();
        is.close();
        //预测时间
        if (!forecastTime.equals("")&&forecastTime!=null) {
            map.put("forecastTime", forecastTime);
        }
        //图片名称
        if (!filename.equals("")&&filename!=null) {
            map.put("filename", filename);
        }
        //图片存放路径
        if (!path.equals("")&&path!=null) {
            if (!filename.equals("")&&filename!=null) {
                map.put("imagePath", path+filename);
            }
        }
        return map;
    }

    public static SimpleDateFormat getSdf1() {
        return sdf1;
    }

    public static void setSdf1(SimpleDateFormat sdf1) {
        GetSatelliteCloudImageTest.sdf1 = sdf1;
    }

    public static SimpleDateFormat getSdf2() {
        return sdf2;
    }

    public static void setSdf2(SimpleDateFormat sdf2) {
        GetSatelliteCloudImageTest.sdf2 = sdf2;
    }

    public static SimpleDateFormat getSdf() {
        return sdf;
    }

    public static void setSdf(SimpleDateFormat sdf) {
        GetSatelliteCloudImageTest.sdf = sdf;
    }

    public static SimpleDateFormat getSdf3() {
        return sdf3;
    }

    public static void setSdf3(SimpleDateFormat sdf3) {
        GetSatelliteCloudImageTest.sdf3 = sdf3;
    } 

}

时间: 2024-10-10 13:16:52

从网页获取图片的相关文章

Python爬虫技术(从网页获取图片)+HierarchicalClustering层次聚类算法,实现自动从网页获取图片然后根据图片色调自动分类—Jason niu

网上教程太啰嗦,本人最讨厌一大堆没用的废话,直接上,就是干! 网络爬虫?非监督学习? 只有两步,只有两个步骤? Are you kidding me? Are you ok? 来吧,follow me, come on! 第一步:首先,我们从网上获取图片自动下载到自己电脑的文件内,如从网址,下载到F:\File_Python\Crawler文件夹内,具体代码请查看http://www.cnblogs.com/yunyaniu/p/8244490.html 第二步:我们利用非监督学习的Hierar

php获取网页中图片与DIV内容实例

分享下php获取网页中图片.DIV内容的简单方法,都是通过正则表达式实现的. 1.获取网页中所有的图片: <?php //取得指定位址的內容,并储存至 $text $text=file_get_contents('http://www.jbxue.com/'); //取得所有img标签,并储存至二维数组 $match 中 preg_match_all('/<img[^>]*>/i', $text, $match); //打印出match print_r($match); ?>

使用selenium的方式获取网页中图片的链接和网页的链接,来判断是否是死链(二)

上一篇使用Java正则表达式来判断和获取图片的链接以及跳转的网址,这篇使用selenium的自带的API(getAttribute)来获取网页中指定的内容 实现内容:获取下面所有图片的链接地址以及跳转地址,使用get请求判断是否有死链 页面内容如图: 页面的源码,需要获取页面的href后的地址,以及src后的地址,: 代码实现可以看出图片都在一个div中,实现的思想为:获取控件集合,在获取每一个li下的元素,在获取,在取出数据下的属性名的属性值 public void new_classific

C# 网络编程之webBrowser获取网页url和下载网页中图片

该文章主要是通过C#网络编程的webBrowser获取网页中的url并简单的尝试下载网页中的图片,主要是为以后网络开发的基础学习.其中主要的通过应用程序结合网页知识.正则表达式实现浏览.获取url.下载图片三个功能.而且很清晰的解析了每一步都是以前一步为基础实现的. 一.界面设计 界面设计如下图所示,添加控件如图,设置webBrowser1其Anchor属性为Top.Bottom.Left.Right,实现对话框缩放;设置groupBox1其Dock(定义要绑到容器控件的边框)为Buttom,实

Object-c 遍历网页获取网页中&lt;img&gt;标签中的图片url

前言: 项目中遇见一个需求遍历网页中所有的<img>标签并且去处图片的url 第一步:编写获取<img >标签的正则表达式,代码如下: -(NSArray*)getImgTags:(NSString *)htmlText { if (htmlText == nil) { return nil; } NSError *error; NSString *regulaStr = @"<img[^>]+src\\s*=\\s*['\"]([^'\"

AsyncHttpClient 获取图片和网页数据演示

AsyncHttpClient 极其好用,采用回调的方式并且是异步的,UI线程已经封装好. https://github.com/loopj/android-async-http 这个例子较为简单. 先看运行结果 点击按钮 从网络上获取图片和baidu首页显示出来. 项目是直接用的源码,为了研究源码使用的. public class HTTPHelper { public HTTPHelper() { } public void get(String url,ResponseHandlerInt

如何通过js和jquery获取图片真实的宽度和高度

在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往往都是按照图片的原尺寸来展示,如果手机屏幕太小,太大的图就会超出去!这时候有两种解决办法 1.给所有的图片加上这样的样式 .news img{margin:5px auto; display:block;width:100%; height:auto;} 但是这种方式有另外一个问题就是,如果插入的图片本身就很小的话,也会被直接拉伸成100%

爬虫-批量获取图片

python版本:3.0 使用库: import urllib.request  #打开网页的库 import os                  #创建文件夹有关 程序作用:批量爬取煎蛋网上图片 视频链接:链接:http://pan.baidu.com/s/1mhLBwWo 密码:1n51 有一点与视频不同:视频中图片链接为http:打头,实际煎蛋网目前没有http:,会导致无法识别网页类型,不能正确下载,在保存是补上http:即可 基础知识: 1.对于某个网站,网址一般是按顺序编码的比如

将网页另存为图片的Java框架

首先要了解的是java在图像这一块非常弱.用java实现截图倒不难,原理吗就是把当前屏幕存成一个图,然后获取鼠标拉去的想去位置然后把截取的图保存到panel里边,再生成图片即可.那么这里要说什么呢?好吧下面就说几个将网页保存为图片的框架: 1.html2image 网上炒这个还不少呢.我说这个就是原声的java代码进行封装的一个jar包.效果非常差,代码就不贴了网上好多. 2.cobra 如果你不知道这个的话,你应该听说过lobobrowser,纯java实现的浏览器,测试了下,除了启动慢的要死