【发布时间】:2015-10-09 14:47:42
【问题描述】:
我有一个包含 HTML 内容的字符串,我需要获取到 .css 和 .js 文件的所有链接。现在,我正在使用这种模式"(http:.*?.\\.css)" 来获取所有 CSS 链接,但是我如何也可以包含 .js 链接呢?
这是我的完整代码:
List<String> urlList = new ArrayList<String>();
String str = new String(Files.readAllBytes(FileSystems.getDefault().getPath("c:" + File.separator + "nutchfiles" + File.separator + "test.html")));
Pattern p = Pattern.compile("(http:.*?.\\.css)");
Matcher m = p.matcher(str);
while (m.find()) {
LOG.info("matched urls" + m.group());
}
【问题讨论】: