网页解析Jsoup简单使用

public static void main(String[] args) throws IOException {

        //System.out.println("Hello World!");

        /**

         * 获取

         */

        File file = new File("/Users/apple/Desktop/temp.html");

        /**

         * 将网页转化成dom文件

         */

        Document docs = Jsoup.parse(file, "utf-8");

        /**

         * 获取具体对象

         */

        Elements eleImg = docs.select("img");

        System.out.println("@{");

        for (int i = 0; i < eleImg.size(); i++) {

            //获取对象里的属性

            String alt = eleImg.get(i).attr("alt");

            String src = eleImg.get(i).attr("src");

            

            String str = "@{@\"name\":@\""+alt+"\",@\"icon\":@\""+src+"\"},";

            System.out.println(str);

        }

        System.out.println("}");

    }

 

你可能感兴趣的:(JSoup)