querySelector在CasperJs上无法正常工作

时间:2017-11-22 19:53:55

标签: javascript casperjs selectors-api

我试图从CasperJs页面中删除一些链接,我有以下代码。

    // Storing the list of all links that fit the requirements 
    var generalLinks = this.evaluate(function(){
        // Getting name, href & weight of each download link
        var links = [].map.call(document.querySelectorAll('div#downloadlist .downbuttonbox > a[data-format]'), function(linkItem) {
            var realName = linkItem.getAttribute("href").split('&title=GenYoutube.net_')[1].split(' ').join('_').split(':').join('').split('#').join('No');
            var weight = linkItem.querySelector("span.label.labelw").textContent ;
            return [realName, linkItem.getAttribute('href'), weight];
        });

        return links;
    });

    // Storing the list of all links that fit the requirements 
    var selectLinks = this.evaluate(function(formatOption){
        // Getting name, href & weight of each select download link
        var links = [].map.call(document.querySelectorAll('div#downloadlist .downbuttonbox > a[data-format="' + formatOption + '"]'), function(linkItem) {
            var realName = linkItem.getAttribute("href").split('&title=GenYoutube.net_')[1].split(' ').join('_').split(':').join('').split('#').join('No');
            var weight = linkItem.querySelector("span.label.labelw").textContent ;
            return [realName, linkItem.getAttribute('href'), weight];
        });    

        return links;
    }, formatOption);

    var listOfLinks = [generalLinks, selectLinks];

我需要在listOfLinks[0]所有链接中存储,并在listOfLinks[1]中过滤链接。

问题是selectLinks变量获取链接正常,但generalLinks变为空。为什么呢?!

两个变量之间的唯一区别是这些行:

var links = [].map.call(document.querySelectorAll('div#downloadlist .downbuttonbox > a[data-format]'), function(linkItem) {//...});

var links = [].map.call(document.querySelectorAll('div#downloadlist .downbuttonbox > a[data-format="' + formatOption + '"]'), function(linkItem) {//...});

0 个答案:

没有答案