图片抓取

简单图片抓取,Java实现

点击(此处)折叠或打开

  1. public void getpic(String src,String num,int loc,String alt,String category,String name) {
  2.         int id = Integer.parseInt(num);
  3.         int id1 = id/1000000;
  4.         int id2 = id/1000;
  5.         String path ="F:\\image\\"+id1+"\\"+id2+"\\"+num+"\\";
  6.         File cate = new File(path);
  7.         if (!cate.exists()&&!cate.isDirectory()) {
  8.             cate.mkdirs();
  9.         }
  10.         String target = path+loc+".png";
  11.         File file = new File(target);
  12.         //System.out.println("url "+src);

  13.         //System.out.println(target);

  14.         try {
  15.             URL url = new URL(src);
  16.             HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  17.             InputStream inputStream=httpURLConnection.getInputStream();
  18.             byte[] bs = new byte[1024];
  19.             int len;
  20.             OutputStream outputStream = new FileOutputStream(file, true);
  21.             while ((len=inputStream.read(bs))!=-1) {
  22.                 outputStream.write(bs, 0, len);
  23.             }
  24.             outputStream.close();
  25.             inputStream.close();
  26.             httpURLConnection.disconnect();
  27.             BufferedImage bufferedImage = ImageIO.read(file);
  28.             int width = bufferedImage.getWidth();
  29.             int height = bufferedImage.getHeight();
  30.                     } catch (Exception e) {
  31.             // TODO: handle exception

  32.              //e.printStackTrace();

  33.             return ;
  34.         }
  35.     }

简单实例,保存时可修改格式。
<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
阅读(32) | 评论(0) | 转发(0) |
0

上一篇:网页解析

下一篇:简单表达式翻译器

给主人留下些什么吧!~~
评论热议
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值