繁体   English   中英

发现很难从表中提取数据(JSoup)

[英]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.

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