Jsuop進行鏈接提取
作者:張勇波
博主發(fā)表的文章,有的是自己原創(chuàng),有的是這些年本人從網(wǎng)上積累的,方便大家學習。
- // 檢索WebContent中的圖片和附件
- Document doc = Jsoup.parse(info.getWebc().getWebContent());
- // 當前頁中的圖片
- Elements srcLinks = doc.select("img[src]");
- String imagesPath = "";
- for (Element link : srcLinks) {
- // 剔除標簽,只剩鏈接路徑
- String imagesPaths = link.attr("src");
- String ht = imagesPaths.substring(0, 4);
- String htt = imagesPaths.substring(0, 1);
- if (!ht.equals("http") && htt.equals("/")) {
- imagesPath = imagesPaths.trim().replaceAll(ContextPath, "");
- imagesPath = imagesPath.substring(imagesPath.lastIndexOf("/") + 1);
- } else {
- imagesPath = "";
- }
- //System.out.println("---導入WebContent中的圖片---" + imagesPath);
- if (!imagesPath.equals("")) {
- importCopy("/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/"+imagesPath, path, strInfoID,"/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/");
- }
- }
- // 提取所有的href連接
- String filePaths = "";
- Elements linehrefs = doc.select("a[href]");
- for (Element link : linehrefs) {
- filePaths = link.attr("href").trim().replaceAll(ContextPath, "");
- filePaths = filePaths.substring(filePaths.lastIndexOf("/") + 1);
- //System.out.println("---導入WebContent中的文件---" + filePaths);
- if (!filePaths.equals("")) {
- importCopy("/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/"+filePaths, path, strInfoID,"/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/");
- }
- }
【本文是51CTO專欄作者張勇波的原創(chuàng)文章,轉載請通過51CTO獲取作者授權】
責任編輯:武曉燕
來源:
上下求索的Z先生博客