首页 > 代码库 > 【图片】批量获取几百张图片

【图片】批量获取几百张图片

用途:需要图片时我们经常是去百度里随便找几张,次数多了就有点烦了,这个工具类就是批量获取几百张图片的url和描述。
  1. public class PicUrls {
  2. public static ArrayList<BasicPicBean> getPicList() {
  3. ArrayList<UrlBean> beans = new ArrayList<>();
  4. beans.addAll(Arrays.asList(beans0));
  5. beans.addAll(Arrays.asList(beans1));
  6. beans.addAll(Arrays.asList(beans2));
  7. beans.addAll(Arrays.asList(beans3));
  8. ArrayList<BasicPicBean> urlList = new ArrayList<>();
  9. for (UrlBean bean : beans) {
  10. urlList.addAll(getPicList(bean));
  11. }
  12. return urlList;
  13. }
  14. private static ArrayList<BasicPicBean> getPicList(UrlBean bean) {
  15. ArrayList<BasicPicBean> picList = new ArrayList<>();
  16. for (int i = 0; i < bean.picCount; i++) {
  17. String picIndex = "" + (bean.picIndexFrom + i);
  18. if (bean.isWith0 && bean.picIndexFrom + i <= 9) picIndex = "0" + picIndex;
  19. String picUrl = bean.host + bean.urlHeader + picIndex + bean.urlEnder;//例如.../1.jpg
  20. if (bean.picWidth > 0) picUrl = picUrl + "!" + bean.picWidth + bean.urlEnder;//例如.../1.jpg!960.jpg
  21. picList.add(new BasicPicBean(bean.picDes, picUrl));
  22. }
  23. return picList;
  24. }
  25. //******************************************************************************************
  26. private static final String HOST0 = "http://img1.mm131.com/pic/";//网站【http://www.mm131.com/】
  27. private static final String HOST1 = "http://img.mmjpg.com/";//网站【http://www.mmjpg.com/】
  28. private static final String HOST2 = "http://pic.meituba.com/uploads/allimg/";//网站【】
  29. private static final String HOST3 = "http://pic2116.ytqmx.com:82/";//网站【http://www.5442.com/】
  30. private static final UrlBean[] beans0 = {
  31. //http://img1.mm131.com/pic/2016/1.jpg
  32. new UrlBean.Builder().host(HOST0).urlHeader("996/").picIndexFrom(1).picCount(9).picDes("北影校花余雨高清写真图片").build(),
  33. new UrlBean.Builder().host(HOST0).urlHeader("2958/").picIndexFrom(2).picCount(23).picDes("童颜嫩妹桃子黑丝大尺度诱惑").build(),
  34. new UrlBean.Builder().host(HOST0).urlHeader("2939/").picCount(23).picDes("清纯少女刘奕宁酥胸覆白色内衣").build(),
  35. new UrlBean.Builder().host(HOST0).urlHeader("2343/").picCount(23).picDes("萌妹销魂写真身材惹火让人欲罢不能").build(),
  36. new UrlBean.Builder().host(HOST0).urlHeader("2935/").picCount(23).picDes("性感女神杨晨晨透视睡衣大胆秀乳").build(),
  37. };
  38. private static final UrlBean[] beans1 = {
  39. //http://img.mmjpg.com/2015/210/1.jpg
  40. new UrlBean.Builder().host(HOST1).urlHeader("2015/444/").picCount(31).picDes("模范学院美少女柳侑绮制服大片").build(),
  41. new UrlBean.Builder().host(HOST1).urlHeader("2015/74/").picCount(38).picDes("极品女神可儿私拍秀完美身材").build(),
  42. new UrlBean.Builder().host(HOST1).urlHeader("2017/990/").picCount(47).picDes("香艳妹子雪白的美胸绝对让你大饱眼福").build(),
  43. new UrlBean.Builder().host(HOST1).urlHeader("2017/962/").picCount(37).picDes("真诱人啊!女神雪白的美胸看着很有感觉").build(),
  44. new UrlBean.Builder().host(HOST1).urlHeader("2017/936/").picCount(37).picDes("身材娇美纯天然美女小叶子美胸艺术照").build(),
  45. };
  46. private static final UrlBean[] beans2 = {
  47. //http://pic.meituba.com/uploads/allimg/2016/07/30/43_485.jpg
  48. new UrlBean.Builder().host(HOST2).urlHeader("2015/10/23/2").picIndexFrom(47).picCount(12).picDes("呆萌可爱的哆啦A梦动漫").build(),
  49. new UrlBean.Builder().host(HOST2).urlHeader("2016/05/26/43_3").picIndexFrom(68).picCount(6).picDes("热血动漫龙珠帅气动漫").build(),
  50. new UrlBean.Builder().host(HOST2).urlHeader("2016/03/25/43_205").picIndexFrom(74).picCount(5).picDes("海贼王红发香克斯动漫").build(),
  51. new UrlBean.Builder().host(HOST2).urlHeader("2016/09/08/43_4").picIndexFrom(76).picCount(12).picDes("可爱快乐的女孩动漫").build(),
  52. new UrlBean.Builder().host(HOST2).urlHeader("2016/07/30/43_4").picIndexFrom(85).picCount(12).picDes("精选超萌小猫咪").build(),
  53. };
  54. private static final UrlBean[] beans3 = {
  55. //http://pic2116.ytqmx.com:82/2017/0531/21/1.jpg!960.jpg
  56. new UrlBean.Builder().host(HOST3).urlHeader("2017/0531/21/").picCount(9).picWidth(960).picDes("德国美景风景壁纸").build(),
  57. new UrlBean.Builder().host(HOST3).urlHeader("2017/0531/21/").picCount(9).picDes("德国美景风景壁纸").build(),//加载对应原图
  58. new UrlBean.Builder().host(HOST3).urlHeader("2016/0829/38/").picCount(15).picWidth(960).picDes("宋茜清纯桌面壁纸").build(),
  59. new UrlBean.Builder().host(HOST3).urlHeader("2017/0531/9/").picCount(4).picDes("王丽坤优雅亮相 被赞坐姿教科书").build(),
  60. new UrlBean.Builder().host(HOST3).urlHeader("2017/0602/38/").picCount(10).picDes("性感爆乳美女户外美照").build(),
  61. };
  62. //******************************************************************************************
  63. static class UrlBean {
  64. public String picDes;//图片描述
  65. public String host;//存放图片的主机地址
  66. public String urlHeader;
  67. public String urlEnder;//默认为= ".jpg"
  68. public int picCount;//此系列图片的数量。所有图片都是以数字命名的,比如1.jpg、2.jpg
  69. public int picIndexFrom;//此系列图片开始的序号位置,默认为1
  70. public int picWidth;//图片宽度
  71. public boolean isWith0;//如,当为01.jpg时是否包含前面的0。默认不包含
  72. private UrlBean(Builder builder) {
  73. picDes = builder.picDes;
  74. host = builder.host;
  75. urlHeader = builder.urlHeader;
  76. urlEnder = builder.urlEnder;
  77. picCount = builder.picCount;
  78. picIndexFrom = builder.picIndexFrom;
  79. picWidth = builder.picWidth;
  80. isWith0 = builder.isWith0;
  81. }
  82. static final class Builder {
  83. private String picDes = "包青天作品";
  84. private String host = "";
  85. private String urlHeader = "";
  86. private String urlEnder = ".jpg";//默认为".jpg"
  87. private int picCount = 1;
  88. private int picIndexFrom = 1;
  89. private int picWidth = 0;
  90. private boolean isWith0 = false;
  91. public Builder() {
  92. }
  93. public Builder urlHeader(String val) {
  94. urlHeader = val;
  95. return this;
  96. }
  97. public Builder urlEnder(String val) {
  98. urlEnder = val;
  99. return this;
  100. }
  101. public Builder picCount(int val) {
  102. picCount = val;
  103. return this;
  104. }
  105. public Builder picIndexFrom(int val) {
  106. picIndexFrom = val;
  107. return this;
  108. }
  109. public Builder picWidth(int val) {
  110. picWidth = val;
  111. return this;
  112. }
  113. public Builder isWith0(boolean val) {
  114. isWith0 = val;
  115. return this;
  116. }
  117. public Builder host(String val) {
  118. host = val;
  119. return this;
  120. }
  121. public Builder picDes(String val) {
  122. picDes = val;
  123. return this;
  124. }
  125. public UrlBean build() {
  126. return new UrlBean(this);
  127. }
  128. }
  129. }
  130. //******************************************************************************************
  131. public static class BasicPicBean {
  132. public String name;
  133. public String url;
  134. public BasicPicBean(String name, String url) {
  135. this.name = name;
  136. this.url = url;
  137. }
  138. }
  139. }
2017-6-5


null


【图片】批量获取几百张图片