@@ -0,0 +1,2286 @@
+package com.virjar.sipsoup.function.select;%0A%0Aimport com.google.common.collect.Lists;%0Aimport com.google.common.collect.Maps;%0Aimport com.google.common.collect.Sets;%0Aimport com.virjar.sipsoup.model.SIPNode;%0Aimport com.virjar.sipsoup.model.XpathNode;%0Aimport org.apache.commons.lang3.StringUtils;%0Aimport org.jsoup.nodes.Element;%0Aimport org.jsoup.select.Collector;%0Aimport org.jsoup.select.Elements;%0Aimport org.jsoup.select.Evaluator;%0A%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0A/**%0A * Created by virjar on 17/7/28.%3Cbr/%3E%0A * %E6%8A%BD%E5%8F%96%E6%96%87%E6%9C%AC%E4%B8%AD%E7%9A%84%E6%89%80%E6%9C%89URL,%E5%90%8C%E6%97%B6%E8%A7%A3%E5%86%B3%E7%9B%B8%E5%AF%B9%E8%B7%AF%E5%BE%84%E7%9A%84%E9%97%AE%E9%A2%98,%E8%AF%B7%E6%B3%A8%E6%84%8FJsoup%E7%9A%84%E8%A7%A3%E6%9E%90%E5%85%A5%E5%8F%A3,%E9%9C%80%E8%A6%81%E4%BC%A0%E9%80%92%E6%96%87%E6%A1%A3URL%E6%89%8D%E8%A1%8C%0A * @author virjar%0A * @since 1.4%0A */%0Apublic class AllUrlFunction implements SelectFunction %7B%0A    private static Map%3CString,String%3E urlAttrkey = Maps.newHashMap();%0A    static %7B%0A        urlAttrkey.put(%22a%22,%22href%22);%0A        urlAttrkey.put(%22link%22,%22href%22);%0A        urlAttrkey.put(%22script%22,%22src%22);%0A        urlAttrkey.put(%22img%22,%22src%22);%0A        urlAttrkey.put(%22iframe%22,%22src%22);%0A    %7D%0A    @Override%0A    public List%3CSIPNode%3E call(XpathNode.ScopeEm scopeEm, Elements elements, List%3CString%3E args) %7B%0A        List%3CElement%3E candidates = Lists.newLinkedList();%0A        for(Element el:elements)%7B%0A            candidates.addAll(Collector.collect(urlContainerEvaluator,el));%0A        %7D%0A        List%3CSIPNode%3E ret = Lists.newLinkedList();%0A        for(Element el:candidates)%7B%0A            String url = el.absUrl(urlAttrkey.get(el.tagName()));%0A            if(StringUtils.isNotBlank(url))%7B%0A                ret.add(SIPNode.t(url));%0A            %7D%0A        %7D%0A        return ret;%0A    %7D%0A%0A    @Override%0A    public String getName() %7B%0A        return %22allUrl%22;%0A    %7D%0A%0A    private static URLContainerEvaluator urlContainerEvaluator = new URLContainerEvaluator();%0A%0A    private static class URLContainerEvaluator extends Evaluator%7B%0A        private static Set%3CString%3E urlContainerTags = Sets.newHashSet();%0A        static %7B%0A            urlContainerTags.add(%22a%22);//%E8%B6%85%E9%93%BE%E6%8E%A5%0A            urlContainerTags.add(%22script%22);//js %E6%A0%87%E7%AD%BE%0A            urlContainerTags.add(%22link%22);//css%E6%A0%B7%E5%BC%8F%E9%93%BE%E6%8E%A5%0A            urlContainerTags.add(%22img%22);//%E5%9B%BE%E7%89%87%0A            urlContainerTags.add(%22iframe%22);//%E6%A1%86%E6%9E%B6%E9%9B%86%0A        %7D%0A        @Override%0A        public boolean matches(Element root, Element element) %7B%0A            return urlContainerTags.contains(element.tagName());%0A        %7D%0A    %7D%0A%7D%0A

支持抽取一个html文档里面的所有URL,且解决URL相对路径问题