Скребковый стол с выпуском JSOUP - PullRequest
0 голосов
/ 24 января 2012

Я использую JSOUP для сбора данных из таблицы на сайте, которая содержит имя игрока и статистику.Я могу выскоблить имя с успехом, но когда я запускаю свою итерацию через ряд, он всегда собирает одинаковую статистику для каждого игрока

Есть идеи?

Источник сайта:

<tr id="plyr22" class="pncPlayerRow playerTableBgRow0"><td class="playertableData">1</td><td class="playertablePlayerName" id="playername_22" style=""><a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="null" leagueId="0" playerId="22" teamId="-2147483648" cache="true">Kobe Bryant</a>, LAL&nbsp;SG<a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="1" leagueId="0" playerId="22" teamId="-2147483648" cache="true"><img src="http://g.espncdn.com/s/fbalm/12/images/icons/sml/news_recent.png" height="12" width="15" border="0" style="margin:0 6px 0 6px" title="Recent News" /></a></td><td class="sectionLeadingSpacer"></td><td class="playertableData">0.63</td><td class="playertableData">2.41</td><td class="playertableData">1.44</td><td class="playertableData">1.29</td><td class="playertableData">2.82</td><td class="playertableData">1.84</td><td class="playertableData">0.18</td><td class="playertableData">4.81</td><td class="playerTableSpacerCell"></td><td class="playertableData sortedCell">15.41</td></tr><tr id="plyr167" class="pncPlayerRow playerTableBgRow1"><td class="playertableData">2</td><td class="playertablePlayerName" id="playername_167" style=""><a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="null" leagueId="0" playerId="167" teamId="-2147483648" cache="true">Joe Johnson</a>, Atl&nbsp;SG, SF<a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="2" leagueId="0" playerId="167" teamId="-2147483648" cache="true"><img src="http://g.espncdn.com/s/fbalm/12/images/icons/sml/video_breaking.png" height="11" width="19" border="0" style="margin:0 6px 0 6px" title="Breaking Video" /></a></td><td class="sectionLeadingSpacer"></td><td class="playertableData">-0.62</td><td class="playertableData">1.70</td><td class="playertableData">3.41</td><td class="playertableData">0.41</td><td class="playertableData">1.48</td><td class="playertableData">0.79</td><td class="playertableData">0.04</td><td class="playertableData">2.27</td><td class="playerTableSpacerCell"></td><td class="playertableData sortedCell">9.47</td></tr><tr id="plyr265" class="pncPlayerRow playerTableBgRow0"><td 

Код:

public static void main(String[] args) throws IOException, SQLException,
        InterruptedException {
    Document doc = Jsoup.connect(html).get();
    String title = doc.title();
    System.out.println(title);
    int tdCount = 1;
    String name = null;
    Double stat1 = null;
    Double stat2 = null;
    Double stat3 = null;
    Double stat4 = null;
    Double stat5 = null;
    Double stat6 = null;
    Double stat7 = null;
    Double stat8 = null;
    Double stat9 = null;
    Double stat10 = null;

    Iterator<Element> trSIter = doc.select("table.playerTableTable")
            .iterator();
    while (trSIter.hasNext()) {
        Element trEl = trSIter.next().child(0);
        Elements tdEls = trEl.children();
        Iterator<Element> tdIter = tdEls.select("tr").iterator();
        boolean firstRow = true;
        while (tdIter.hasNext()) {

            Element tr = (Element) tdIter.next();
            if (firstRow) {
                firstRow = false;
                continue;
            }

            while (tdIter.hasNext()) {

                System.out.println("============================");
                Element tdEl = tdIter.next();
                name = tdEl.getElementsByClass("playertablePlayerName")
                        .text();
                System.out.println("Name: " + name);

                // System.out.println(tdEl);
                Elements tdsEls = tdEl.select("td.playertableData");
                Iterator<Element> columnIt = tdsEls.iterator();
                boolean firstRow1 = true;
                while (columnIt.hasNext()) {

                    Element td = (Element) columnIt.next();
                    if (firstRow1) {
                        firstRow1 = false;
                        continue;
                    }

                    while (columnIt.hasNext()) {

                        Element column = columnIt.next();
                        switch (tdCount++) {

                        case 1:
                            stat1 = Double.parseDouble(column.text());
                            break;
                        case 2:
                            stat2 = Double.parseDouble(column.text());
                            break;
                        case 3:
                            stat3 = Double.parseDouble(column.text());
                            break;
                        case 4:
                            stat4 = Double.parseDouble(column.text());
                            break;
                        case 5:
                            stat5 = Double.parseDouble(column.text());
                            break;
                        case 6:
                            stat6 = Double.parseDouble(column.text());
                            break;
                        case 7:
                            stat7 = Double.parseDouble(column.text());
                            break;
                        case 8:
                            stat8 = Double.parseDouble(column.text());
                            break;
                        case 9:
                            stat9 = Double.parseDouble(column.text());
                            break;
                        case 10:
                            stat10 = Double.parseDouble(column.text());
                            break;
                        }

                        // System.out.print(column.className()+":"+column.text()+",");
                        System.out.print("stat1: " + stat1 + " stat2: "
                                + stat2 + " stat3: " + stat3 + " stat4: "
                                + stat4 + " stat5: " + stat5 + " stat6: "
                                + stat6 + " stat7: " + stat7 + " stat8: "
                                + stat8 + " stat9: " + stat9 + " stat10: "
                                + stat10);
                    }
                }
                System.out.println();

            }
            System.out.println();

        }
    }
}

My OutPut

Игрок Rater - Бесплатный Fantasy Basketball - ESPN

Имя: Коби Брайант, LAL SG

stat1: 2,41 stat2: null stat3: null stat4: null stat5: null stat6: null stat7: null stat8: null stat9: null stat10: nullstat1: 2.41 stat2: 1.44 stat3: null stat4: null stat5: null stat6: null stat7: нулевой stat8: нулевой stat9: нулевой stat10: нулевой статус1: 2.41 stat2: 1.44 stat3: 1.29 stat4: нулевой stat5: нулевой stat6: нулевой stat7: нулевой stat8: нулевой stat9: нулевой stat10: нулевой статус1: 2.41 stat2: 1.44 stat3: 1.29 stat4:2.82 stat5: null stat6: null stat7: null stat8: null stat9: null stat10: nullstat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: ноль stat7: нулевой stat8: ноль stat9: нулевой stat10: нольstat1: 2.41stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1,84 stat6: 0,18 stat7: null stat8: null stat9: null stat10: nullstat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: ноль stat9: нулевой stat10: нульстат1: 2.41 stat2:1,44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: null stat10: null

Имя: Джо Джонсон, Atl SG, SF

stat1: 2,41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: nullstat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2:1,44 стат3: 1,29 сТат4: 2,82 Стат5: 1,84 Стат6: 0,18 Стат7: 4,81 Стат8: 15,41 Стат9: 1,7 Стат10: 3,41 Стат1: 2,41 Стат2: 1,44 Стат3: 1,29 Стат4: 2,82 Стат5: 1,84 Стат6: 0,18 Стат7: 4,81 Стат8: 15,41 Стат9: 1,7 Стат3.41стат1: 2,41 стат2: 1,44 стат3: 1,29 стат4: 2,82 стат5: 1,84 стат6: 0,18 стат7: 4,81 стат8: 15,41 стат9: 1,7 ст10: 3,41

Имя: Андре Игуодала, Phi SF, SG

stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat2: 1.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3:1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41стат1: 2.41 стат2:1,44 stat3: 1,29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41

Имя: Джеймс Харден, OKC SG

stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3:1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41стат1: 2.41 стат2: 1.44 стат3: 1.29 стат4: 2.82 стат5: 1.84 стат6: 0.18 стат7: 4.81 стат8: 15.41 стат9: 1.7 стат10: 3.41 стат1: 2.41 стат2: 1.44 стат3: 1.29 стат4: 2.82 стат5: 1.84 стат6: 0.18stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41

Имя:Монта Эллис, GS PG,SG

stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat2: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8:15.41 stat9: 1.7 stat10: 3.41 stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41

Имя: КевинМартин, Хоу SG

stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7:4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41 stat2: 1.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41stat1: 2.41 stat2: 1.44 stat3: 1.29 stat4: 2.82 stat5: 1.84 stat6: 0.18 stat7: 4.81 stat8: 15.41 stat9: 1.7 stat10: 3.41

1 Ответ

0 голосов
/ 24 января 2012

Вы забыли сбросить tdCount при переходе к следующему ряду.

...