[英]Finding it difficult to extract data from table (JSoup)
當我在網站上搜尋元素時,我的代碼沒有返回任何內容。 我以前已經成功檢索了該網站上的表格。 但是,我似乎無法從Fantasy.premierleague.com上的這些“動態表”中提取代碼。
http://i.imgur.com/cHkFwHE.png <我試圖提取的圖片。
另外,我的登錄詳細信息會合法顯示在代碼中,以便你們可以使用我的憑據登錄並親自查看發生了什么。 (這是一個備用的模擬帳戶)。
public class StatsCollector {
public static void main (String [] args){
try {
String url = "https://users.premierleague.com/PremierUser/j_spring_security_check";
Response res = Jsoup
.connect(url)
.followRedirects(false)
.timeout(2_000)
.data("j_username", "<fantasyfootball123@guerrillamail.com>")
.data("j_password", "<fantasy123>")
.method(Method.POST)
.execute();
Map<String, String> loginCookies = res.cookies();
String url1 = "http://fantasy.premierleague.com/stats/elements/?page=1" ;
Document doc = Jsoup.connect
(url1)
.cookies(loginCookies)
.get();
for (Element table: doc.select("table.ismEiwMatchesPast")) {
for (Element tbody: table.select("tbody.ismHistoryPastSeasons")) {
for (Element row: table.select("tr")){
Elements tds = row.select("td");
if (tds.size()>2){
System.out.println(tds.get(0).text() + " : " + tds.get(1).text() + " : " + tds.get(2).text());
}
}
}
}
}
catch (IOException ex) {
Logger.getLogger(StatsCollector.class.getName()).log(Level.SEVERE,null,ex);
}
}
}
內容是動態創建的,您還可以使用硒 “獲取”來獲取請求的數據,然后就可以解析它(使用Jsoup或其他方法)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.