快遞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;
        
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM