坤木华 发表于 2012-11-17 23:42:23

求助,源文件里用javascript得来的数据怎么采集啊

要采集这个网站http://www.okooo.com/match/1/211466/history/
采集数据为: 5胜4平1负,其中主场2胜2平0负
源文件里用 javascript得来的,我不懂啊。各路大神来拯救下吧。

坤木华 发表于 2012-11-18 09:39:25

路过的大神啊,帮看看呀

塞北的雪 发表于 2012-11-18 15:43:19

$().ready(function () {
    var homecompobj = $(".homecomp");
    var awaycompobj = $(".awaycomp");
    var vscompobj = $(".vscomp");
    var hometrobj = homecompobj.find("tr");
    var awaytrobj = awaycompobj.find("tr");
    var vstrobj = vscompobj.find("tr");
    var teamname = 0;
    var homeindex = 2;
    var awayindex = 4;
    var recordindex = 3;
    if (GetCookie('historyShowThisMatch') == 1) {
      $('#jsSetVisible').attr('checked', true);
      $('.jsThisMatch').show();
    } else {
      $('#jsSetVisible').attr('checked', false);
      $('.jsThisMatch').hide();
    }
    $('#jsSetVisible').click(function () {
      if (this.checked) {
            SetCookie('historyShowThisMatch', 1, 100 * 24 * 60 * 60, '/');
            $('.jsThisMatch').show();
            google_p();
      } else {
            SetCookie('historyShowThisMatch', 0, 100 * 24 * 60 * 60, '/');
            $('.jsThisMatch').hide();
            google_p();
      }
    })

    function gethomerecord(team, returnid, trobj) {
      var victory = 0;
      var failure = 0;
      var draw = 0;
      var homevictory = 0;
      var homefailure = 0;
      var homedraw = 0;
      for (var i = 3, ilen = trobj.length; i < ilen; i++) {
            if ($(trobj).css("display") == "none") continue;
            var datasarr = $(trobj).attr("attr").split(",");
            var recordval = datasarr;
            if (recordval == "-") continue;
            var recordarr = recordval.split("-");
            var homescore = Number(recordarr);
            var awayscore = Number(recordarr);
            var homeid = $(trobj).find("td").eq(homeindex).attr("attr");
            var awayid = $(trobj).find("td").eq(awayindex).attr("attr");
            if (returnid == homeid) {
                var checkscore = homescore - awayscore;
                if (checkscore > 0) {
                  homevictory++;
                } else if (checkscore < 0) {
                  homefailure++;
                } else if (checkscore == 0) {
                  homedraw++
                }
            } else if (returnid == awayid) {
                var checkscore = awayscore - homescore;
            }
            if (checkscore > 0) {
                victory++;
            } else if (checkscore < 0) {
                failure++;
            } else if (checkscore == 0) {
                draw++
            }
      }
      if (team != "away") {
            var gethtml = victory + "胜" + draw + "平" + failure + "负,其中主场" + homevictory + "胜" + homedraw + "平" + homefailure + "负";
      } else {
            var gethtml = victory + "胜" + draw + "平" + failure + "负,其中客场" + (victory - homevictory) + "胜" + (draw - homedraw) + "平" + (failure - homefailure) + "负";
      }
      return gethtml;
    }

    function getscorehtml(team, returnid, trobj) {
      $("." + team + "score").html(gethomerecord(team, returnid, trobj));
    }
    getscorehtml("home", host_team_id, hometrobj);
    getscorehtml("away", guest_team_id, awaytrobj);
    getscorehtml("vs", host_team_id, vstrobj);
    $("#HomeLeagueFilter").change(function () {
      filter(hometrobj, "Home", host_team_id, $(this));
      getscorehtml("home", host_team_id, hometrobj);
    });
    $("#HomeFilter").change(function () {
      filter(hometrobj, "Home", host_team_id, $(this));
      getscorehtml("home", host_team_id, hometrobj);
    });
    $("#HomeCount").change(function () {
      filter(hometrobj, "Home", host_team_id, $(this));
      getscorehtml("home", host_team_id, hometrobj);
    });
    $("#AwayLeagueFilter").change(function () {
      filter(awaytrobj, "Away", guest_team_id, $(this));
      getscorehtml("away", guest_team_id, awaytrobj);
    });
    $("#AwayFilter").change(function () {
      filter(awaytrobj, "Away", guest_team_id, $(this));
      getscorehtml("away", guest_team_id, awaytrobj);
    });
    $("#AwayCount").change(function () {
      filter(awaytrobj, "Away", guest_team_id, $(this));
      getscorehtml("away", guest_team_id, awaytrobj);
    });
    $("#VsLeagueFilter").change(function () {
      filter(vstrobj, "Vs", host_team_id, $(this));
      getscorehtml("vs", host_team_id, vstrobj);
    });
    $("#VsFilter").change(function () {
      filter(vstrobj, "Vs", host_team_id, $(this));
      getscorehtml("vs", host_team_id, vstrobj);
    });
    $("#VsCount").change(function () {
      filter(vstrobj, "Vs", host_team_id, $(this));
      getscorehtml("vs", host_team_id, vstrobj);
    });

    function filter(trobj, team, idval, curobj) {
      var teamval = $("#" + team + "LeagueFilter").val();
      var haval = $("#" + team + "Filter").val();
      var conval = $("#" + team + "Count ").val();
      var checki = 0;
      for (var i = 3, ilen = trobj.length; i < ilen; i++) {
            var teamtext = $(trobj).find("td").eq(teamname).text().trim();
            var datasarr = $(trobj).attr("attr").split(",");
            var homeid = datasarr;
            var awayid = datasarr;
            var isFriendly = $(trobj).attr('data-lt');
            if (teamval == 'notFriendly' && isFriendly == 'friend') {
                $(trobj).hide();
                continue;
            }
            if (teamval != "all" && teamval != 'notFriendly' && teamtext != teamval) {
                $(trobj).hide();
                continue;
            }
            if (haval != "all" && haval == "Away") {
                if (awayid != idval) {
                  $(trobj).hide();
                  continue;
                }
            } else if (haval != "all" && haval == "Home") {
                if (homeid != idval) {
                  $(trobj).hide();
                  continue;
                }
            }
            checki++;
            if (checki > Number(conval)) {
                $(trobj).hide();
                continue;
            }
            $(trobj).show();
      }
      google_p();
    }
});

function showTable(ID, TotalCount) {
    for (var I = 1; I <= TotalCount; I++) {
      if (I == ID) {
            document.getElementById("Table" + I).style.display = "";
      } else {
            document.getElementById("Table" + I).style.display = "none";
      }
    }
}关键代码,这个是利用jQuery动态生成的,十分难搞啊……

http://img1.okoooimg.com/min/?b=JS&f=dataanalysis%2ffootcompetitionhistory.js&v=201211151048

坤木华 发表于 2012-11-18 19:18:47

塞北的雪 发表于 2012-11-18 15:43 static/image/common/back.gif
关键代码,这个是利用jQuery动态生成的,十分难搞啊……

http://img1.okoooimg.com/min/?b=JS&f=dataana ...

多谢了,十二分感谢!
这个问题看来确实是很难了:Q
页: [1]
查看完整版本: 求助,源文件里用javascript得来的数据怎么采集啊