zoukankan      html  css  js  c++  java
  • 快递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;
            
        }
  • 相关阅读:
    Oracle exp/imp导出导入工具的使用
    导入导出数据语句小结
    改变一生的五句话
    给年轻工程师的十大忠告
    项目经理三步曲(项目经理成长版)
    写作、写程序的快乐和痛苦
    《Excel与VBA程序设计(mini版)》
    《3S新闻周刊》第三期发布: 解密Google Earth
    《Excel与VBA程序设计》进度(2006.3.8)
    Arc2Earth正式发布
  • 原文地址:https://www.cnblogs.com/rubekid/p/6611898.html
Copyright © 2011-2022 走看看