1、要抓取資料的地址:
http://sports.sina.com.cn/b/2014-03-23/18047067888.shtml
2、實現代碼:
public class GrabContent { public static ArrayList<HashMap<String, Object>> getDatas(String url) { ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); try { Document doc = Jsoup.connect(url).timeout(8000).get(); Element test = doc.select("tbody").first(); for (int i = 2; i < 18; i++) { HashMap<String, Object> map = new HashMap<String, Object>(); Element team_name = test.child(i); String rank = team_name.child(0).text(); String teamname = team_name.child(1).text(); String round = team_name.child(2).text(); String score = team_name.child(9).text(); map.put("rank", rank); map.put("teamname", teamname); map.put("round", round); map.put("score", score); data.add(map); } } catch (IOException e) { e.printStackTrace(); } return data; } public static void main(String[] args) { System.out.println(getDatas("http://sports.sina.com.cn/b/2014-03-23/18047067888.shtml")); }}