【问题标题】:JSoup get specific data from webpageJSoup 从网页获取特定数据
【发布时间】:2015-02-01 11:09:10
【问题描述】:

我一直在尝试从:http://www.betvictor.com/sports/en/to-lead-anytime 获取数据,我想使用 JSoup 获取匹配列表。

例如: 卡昂 v AS 圣艾蒂安 凯尔特人对流浪者

等等……

我当前的代码是:

String couponPage = "http://www.betvictor.com/sports/en/to-lead-anytime";
Document doc1 = Jsoup.connect(couponPage).get();


    String match = doc1.select("#coupon_143751140 > table:nth-child(3) > tbody > tr:nth-child(2) > td.event_description").text();
    System.out.println("match:" + match);

一旦我弄清楚如何获取一项数据,我会将其放入 for 循环中循环整个表,但首先我需要获取一项数据。

目前,输出是“match:”,所以看起来“match”变量是空的。

非常感谢任何帮助,

【问题讨论】:

    标签: java web-scraping jsoup webpage


    【解决方案1】:

    经过几个小时的试验,我已经弄清楚了如何回答我的问题。结果页面没有立即正确加载,必须实现“超时”方法。

    Document doc;
    try {
    
        // need http protocol
        doc = Jsoup.connect("http://www.betvictor.com/sports/en/football/coupons/100/0/0/43438/0/100/0/0/0/0/1").timeout(10000).get();
    
        // get all links
        Elements matches = doc.select("td.event_description a");
        Elements odds = doc.select("td.event_description a");
        for (Element match : matches) {
    
            // get the value from href attribute
    
            String matchEvent = match.text();
            String[] parts = matchEvent.split(" v ");
            String team1 = parts[0];
            String team2 = parts[1];
            System.out.println("text : " + team1 + " v " + team2);
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-16
      • 1970-01-01
      • 2018-01-27
      • 2018-09-26
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      相关资源
      最近更新 更多