java中解析html jsoup是利器,其中部分用法如下:
选择器
try { Document doc = Jsoup.parse(file,"utf-8"); Elements e = doc.select("img[src$=content_logo.png]"); //所有以content_logo.png结尾的img元素 Elements e2 = doc.select("a[href$=commentAnchor]"); //所有以commentAnchor结尾的a元素 System.out.println(e); } catch (IOException e) { e.printStackTrace(); }
其他操作,参见api