快递100物流公司列表

public static void main(String[] args) throws ClientProtocolException, IOException {
        String html = SimpleHttpClient.get("https://www.kuaidi100.com/network/plist.shtml");
        Pattern pattern = Pattern.compile("<a href=\"(.*?)\" target=\"_blank\"><h4>.*?</h4><b>(.*?)</b>");
        Matcher matcher = pattern.matcher(html);
        JSONObject json = new JSONObject();
        while (matcher.find()) {
            String url = matcher.group(1);
            JSONObject item= parse(url);
            if(item != null){                
                json.put(item.getString("key"), item);
            }
            else{
                System.out.println(url);
            }
        }
        System.out.println(json);
    }

    public static JSONObject parse(String url) throws ClientProtocolException, IOException{
        String html = SimpleHttpClient.get(url);
        Pattern pattern = Pattern.compile("<div class=\"ex-title\">[\\s\\S]*?<h1>(.*?)</h1>[\\s\\S]*?<input type=\"hidden\" id=\"companyCode\" value=\"(.*?)\" />[\\s\\S]*?<font id=\"allcompanytel\" class=\"tel-icon\" title=\"拨打客服电话\">(.*?)</font>&emsp;<a target=\"_blank\" rel=\"nofollow\" id=\"allcompanyurl\" class=\"url-icon\" title=\"访问官网\" href=\"(.*?)\">.*?</a>&emsp;<a target=\"_blank\" class=\"net-icon\" rel=\"nofollow\" id=\"serversite\" title=\"查看快递网点\" href=\".*?\">服务网点</a>[\\s\\S]*?</div>");
        Matcher matcher = pattern.matcher(html);
        
        if (matcher.find()) {
            String name = matcher.group(1);
            String key = matcher.group(2);
            String tel = matcher.group(3);
            String site = matcher.group(4);
            JSONObject item =  new JSONObject();
            item.put("key", key);
            item.put("name", name);
            item.put("tel", tel);
            item.put("site", site);
            return item;
        }
        return null;
        
    }

 

转载于:https://www.cnblogs.com/rubekid/p/6611898.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值