Jsuop进行链接提取

开发 开发工具
博主发表的文章,有的是自己原创,有的是这些年本人从网上积累的,方便大家学习。

 [[178886]]

  1. // 检索WebContent中的图片和附件 
  2.  Document doc = Jsoup.parse(info.getWebc().getWebContent()); 
  3.  // 当前页中的图片 
  4.  Elements srcLinks = doc.select("img[src]"); 
  5.  String imagesPath = ""
  6.  for (Element link : srcLinks) { 
  7.  // 剔除标签,只剩链接路径 
  8.  String imagesPaths = link.attr("src"); 
  9.  String ht = imagesPaths.substring(0, 4); 
  10.  String htt = imagesPaths.substring(0, 1); 
  11.  if (!ht.equals("http") && htt.equals("/")) { 
  12.  imagesPath = imagesPaths.trim().replaceAll(ContextPath, ""); 
  13.  imagesPath = imagesPath.substring(imagesPath.lastIndexOf("/") + 1); 
  14.  } else { 
  15.  imagesPath = ""
  16.  } 
  17.  //System.out.println("---导入WebContent中的图片---" + imagesPath); 
  18.  if (!imagesPath.equals("")) { 
  19.  importCopy("/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/"+imagesPath, path, strInfoID,"/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/"); 
  20.  } 
  21.  } 
  22.  // 提取所有的href连接 
  23.  String filePaths = ""
  24.  Elements linehrefs = doc.select("a[href]"); 
  25.  for (Element link : linehrefs) { 
  26.  filePaths = link.attr("href").trim().replaceAll(ContextPath, ""); 
  27.  filePaths = filePaths.substring(filePaths.lastIndexOf("/") + 1); 
  28.  //System.out.println("---导入WebContent中的文件---" + filePaths); 
  29.  if (!filePaths.equals("")) { 
  30.  importCopy("/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/"+filePaths, path, strInfoID,"/html/"+strSiteID+"/"+strColumnID+"/"+keyID+"/"); 
  31.  } 
  32.  } 

 【本文是51CTO专栏作者张勇波的原创文章,转载请通过51CTO获取作者授权】

责任编辑:武晓燕 来源: 上下求索的Z先生博客
相关推荐

2023-10-20 16:14:43

2011-04-02 14:24:25

SQL Server数网络链接

2020-07-08 15:43:26

数据机器学习提取

2023-11-30 08:36:10

选择器链接设计

2022-08-09 07:57:25

Linux操作系统Windows

2021-11-12 23:44:28

Windows 10Windows微软

2017-01-15 15:27:51

Linux软连接和硬链接

2022-02-28 09:44:09

Linux硬链接软链接

2023-11-15 08:27:46

Linux系统

2017-02-24 11:31:17

Android颜色提取Palette

2018-11-09 10:10:09

Linux硬链接软链接

2019-11-01 11:06:02

Linux操作系统Windows

2018-11-09 10:30:05

Linux硬链接软链接

2020-06-01 19:00:42

Linux软链接硬链接

2009-09-15 14:30:11

Linq连接

2020-07-13 07:30:12

Linux提取文件脚本

2010-05-04 13:09:21

Unix操作系统

2023-03-05 16:36:14

Linux链接目标文件

2022-10-21 08:18:54

Linuxln 命令

2010-05-04 12:25:28

Unix链接
点赞
收藏

51CTO技术栈公众号