一般链接获取每个imdb前250电影的所有细节?

时间:2015-05-08 18:25:23

标签: javascript jquery ajax imdb

对于学校作业我选择使用Ajax动态地将top250列表中的所有电影加载到单个页面,每当我从列表中选择一部电影时,从该页面加载,弹出窗口会显示该电影的详细信息。我想知道的是如何获得所有电影的一般链接,以获取该列表上每部电影的详细信息,因为我坚持使用“The Shawshanks Redemption”链接。这是代码

$(document).ready(function () {



    $.ajax({
        url: "crosscall/crosscall.php",
        data: {
            'url': 'http://www.imdb.com/chart/top?ref_=nv_ch_250_4' //Site van IMDB die de Top 250 toont.
        },
        type: "POST",
        success: function (data) {
            var $data = $(data);
            var titel = $('.titleColumn');
            var nummer = 0;
            var imageURL = 'http://ia.media-imdb.com/images/M/MV5BODU4MjU4NjIwNl5BMl5BanBnXkFtZTgwMDU2MjEyMDE@._V1_SX214_AL_.jpg';
            var imageID = 'image';
            var image = $('.posterColumn td a img').attr('src');
            $(document.body).append('<img id="' + imageID + '">');
            $.ajax({
                url: 'hotlink.php?url=' + imageURL,
                success: function (base64data) {
                    $('#' + imageID).attr('src', 'data:image/png;base64,' + base64data);
                }
            });

            $data.find('.titleColumn').each(function () {
                var titel2 = $(this).find('a').text();
                var datum = $(this).find('span[name=rd]').text();
                var plaats = $(this).find('span[name=ir]').text();
                if (titel2.length > 10) titel2 = titel2.substring(0, 38);

                if (nummer < 250) {
                    $('.container').append('<a href="#" class="popLink"><div class="imgurstyle"><div class="titel"><h1>' + plaats + ' ' + titel2 + ' ' + datum + ' </h1></div><img src="' + imageURL + image + '" alt="image"></div></a>');
                }
            });


            //Als men op een film klikt, zal de popover tevoorschijn komen.
            $("a.popLink").click(function (event) {
                //voorkomt dat het link waarop men zal klikken herlaadt.
                event.preventDefault();
                showPopover1();

            });

            var popoverBG;
            var popover;

            //functie popover maken zoals bij de oefeningen die we hadden behandeld tijdens WC.
            function showPopover1() {
                //maak popoverBG
                popoverBG = document.createElement('div');
                popoverBG.className = 'popoverBG';
                document.body.appendChild(popoverBG);
                //maak popover
                popover = document.createElement('div');
                popover.className = 'popover';




                $.ajax({
                    url: "crosscall/crosscall.php",
                    data: {
                        'url': 'http://www.imdb.com/title/tt0111161/?ref_=chttp_tt_1' //Details van elk filmpagina ophalen.
                    },
                    type: "POST",
                    success: function (data) {
                        //gegevens ophalen in popover steken
                        var $data = $(data);
                        var jaartal = $('.infobar');
                        var nummer = 0;

                        $data.find('.infobar').each(function () {
                            var titel = $(this).parent().find('h1 span[itemprop=name]').text();
                            var jaartal2 = $(this).find('.nobr').text();
                            var rating = $(this).find('div .titlePageSprite star-box-giga-star').appendTo('li');
                            console.log($(this).find('.titlePageSprite star-box-giga-star'));
                            var genre = $(this).find('.itemprop').text();
                            var regisseur = $(this).parent().find('div[itemprop="director"] span ').text();
                            var schrijver = $(this).parent().find('div[itemprop="creator"]  span').text();
                            var acteurs = $(this).parent().find('div[itemprop="actors"] span').text();
                            var meerAct = $(this).parent().find('.see-more inline nobr a[itemprop="url"]').text();
                            var plot = $(this).parent().find('p[itemprop="description"]').text();
                            var tijdsduur = $(this).find('time').text();
                            if (nummer < 250) {
                                popover.innerHTML = '<header><h2>' + titel + '</h2></header><ul><li><img src="images/shawshank%20redemption.jpg" alt="n1"></li><li>Release:' + jaartal2 + '</li><li>User ratings:' + rating + '</li><li>Genre: ' + genre + '</li><li>Duur: ' + tijdsduur + '</li><li>Regisseur: ' + regisseur + '</li><li>Schrijvers:' + schrijver + '</li><li>Acteurs: ' + acteurs + ' <a href="#" target="_blank">' + meerAct + '</a></li><li>' + plot + '</li></ul><p>Meer info klik <a href="http://www.imdb.com/title/tt0111161/?ref_=chttp_tt_1" target="_blank">Hier</a><p><a href="#" onclick="removePopover()">Close</a></p>';

                            }

                        });
                    }
                });
                  document.body.appendChild(popover);
                            //voeg click toe aan popoverBG
                            popoverBG.onclick = removePopover;

                            function removePopover() {
                                document.body.removeChild(popoverBG);
                                document.body.removeChild(popover);
                            };
            };
        }
    });
});

0 个答案:

没有答案