使用casperjs将变量导出到csv

时间:2014-07-02 16:16:35

标签: javascript variables csv casperjs

我有一段代码,它会点击链接,抓取数据,关闭链接,然后重复。它很棒。但是,我正在尝试将lbdes变量连接到longdescription变量,以便将longdescription变量导出到csv中。当我运行代码时,没有任何事情发生,没有错误,只是一个空白的命令提示符出现就像运行正常。

var longdescription = "";


function scheduleScrapeAndClose(){
    casper.waitUntilVisible(x('//*[@id="product-infoform"]'));
    casper.wait(5000, function(){
        lbdes = casper.fetchText(x('//*[@id="product_overview"]'));
        longdescription += lbdes;
        casper.click(x('//*[@id="product-infocloser"]'));
    });
    casper.waitWhileVisible(x('//*[@id="product_overview"]'));
}

casper.then(function(){
    var buttonNumber = casper.getElementsInfo(".button.small.orange").length;
    for(var i = 0; i < buttonNumber; i++) {
        //casper.thenClick('.search-product-image');
        casper.thenClick(x("(//*[contains(@class,'button') and contains(@class,'small') and     contains(@class,'orange')])["+(i+1)+"]"));
        scheduleScrapeAndClose();
    }
});

1 个答案:

答案 0 :(得分:0)

没想到 - 在上面的代码之后添加了一个函数,然后调用变量并且它正常工作。