我想從一個網頁(http://steamcommunity.com/id/Winning117/games/?tab=all)使用特定的標籤,但我一直得到空數據。我期望的結果是獲得特定遊戲「Cluckles的冒險」在這種情況下的「小時數」。任何幫助表示讚賞,感謝:)Jsoup ID選擇不起作用
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class TestScrape {
public static void main(String[] args) throws Exception {
String url = "http://steamcommunity.com/id/Winning117/games/?tab=all";
Document document = Jsoup.connect(url).get();
Element playTime = document.select("div#game_605250").first();
System.out.println(playTime);
}
}
編輯:我怎樣才能知道如果網頁使用JavaScript,因此無法通過Jsoup解析?
試試這個:playTime.select(」 .ellipsis hours_played「) – thanga
@thanga你建議用哪一行代碼替換哪部分?抱歉,我剛剛在昨天開始使用Jsoup,所以我對它不熟悉 –
您正在尋找的數據是使用一些JavaScript代碼動態加載的,因此您無法使用Jsoup進行修改。您需要使用無頭瀏覽器,如PhantomJS。 – TDG