简体   繁体   中英

Finding it difficult to extract data from table (JSoup)

My code is returning nothing when I'm crawling for elements on the website. I have successfully crawled tables on this website previously. However, I can't seem to extract code from these "dynamic tables" on fantasy.premierleague.com.

http://i.imgur.com/cHkFwHE.png < A pic of what i'm trying to extract.

Also, my login details are legitimately shown in the code so you guys can login using my credentials and see for yourself what's going on. (obv it's a spare demo account).

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或其他方法)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM