码迷,mamicode.com
首页 > 编程语言 > 详细

java 对于url地址的实体符号的处理

时间:2016-10-29 12:15:51      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:bsp   escape   decode   epo   ons   nec   htm   out   group   

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
-->


public static String getNextPage(String web) throws Exception {
        HttpComponentsClientHttpRequestFactory factory=new HttpComponentsClientHttpRequestFactory();
//        factory.setConnectTimeout(60000);
//        factory.set
        String regx="上一页</a>)(<a.*?href=[\\\"‘]?(((http|https)?://)?/?[^\\\"‘]+)[\\\"‘]?.*?>(.+)</a>";
        RestTemplate template=new RestTemplate();
        URI uri=new URI(URLDecoder.decode(web,"utf-8"));
        String stri = template.getForObject(uri, String.class);
        Pattern pattern=Pattern.compile(regx);
        Matcher matcher = pattern.matcher(stri);
        matcher.find();
        String group = matcher.group();
        group = group.substring(group.indexOf("href=\"/") + 7, group.indexOf("\" title=\""));
        group="http://www.youbianku.com/"+group;
        group= StringEscapeUtils.unescapeHtml4(group);
        return group;

    }

 

java 对于url地址的实体符号的处理

标签:bsp   escape   decode   epo   ons   nec   htm   out   group   

原文地址:http://www.cnblogs.com/wangyang108/p/6010145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!