2011-11-22 233 views
9

如何提取位於以下位置的表格內容: /id/2/year/2012/acc-conference">http://espn.go.com/mens-college - 籃球/會議/積分榜// id/2/year/2012/acc-conference使用JSoup提取HTML表格內容

我看到的幾個例子並不太清楚如何獲取表格的內容。任何人都可以提供任何幫助?

+0

'http:// espn.go.com/mens-college-basketball/meetings/byings // id/2/year/2012/acc-conference'返回404找不到錯誤:URL你所要求的不存在,但你可能對下面的內容感興趣。你確定這是正確的網址嗎? –

+0

這是錯誤的網址,它是:http://espn.go.com/mens-college-basketball/conferences/standings/_/id/2/year/2012/acc-conference –

回答

15

你現在可能已經解決了這個問題,但是這將會遍歷每個表格並打印出團隊名稱和Win/Loss列,調整你需要的信息第二個表格顯然格式不同,所以如果您需要該表中的不同信息,則需要進一步調整。讓我知道你是否需要任何幫助。

Document doc = Jsoup.connect("http://espn.go.com/mens-college-basketball/conferences/standings/_/id/2/year/2012/acc-conference").get(); 

    for (Element table : doc.select("table.tablehead")) { 
     for (Element row : table.select("tr")) { 
      Elements tds = row.select("td"); 
      if (tds.size() > 6) { 
       System.out.println(tds.get(0).text() + ":" + tds.get(1).text()); 
      } 
     } 
    } 
+0

'Elements'是一個打錯'Element' –

+1

@DonLarynx答案沒有錯誤。 – Stephan