获取图片地址
获取图片
public static int getImg(String stringUrl,String dirNameParam) throws IOException { String agent1 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; Document documentRoot = Jsoup.connect(stringUrl).userAgent(agent1).get(); Elements imgElements = documentRoot.getElementsByClass("zoom"); List<String> list = new ArrayList<String>(); int i = 0; for (Element imgElement : imgElements) { //imgElement.getElementsByClass(""); String imgSrcStr = imgElement.attr("file");//获取到src的值 String imgUrl=""; if(imgSrcStr.contains("!")) { imgUrl = imgSrcStr.split("!")[0]; if(!imgUrl.endsWith("avatar_big.jpg")) { list.add(i, imgUrl);//放入list中 String imgName = getImgNameByTime(dirNameParam); saveImgByPath(imgUrl,imgName); i++; } } } System.out.println(list); return list.size(); }
QQ 3087438119