使用pjscrape刮取图像src属性

时间:2013-01-29 22:47:19

标签: web-scraping phantomjs scraper

我在刮取图像的图像源方面遇到了一些困难。我尝试了以下方法:

_pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(7) img.attributes.src')

以及

_pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(7) img[src]')

但似乎没有任何效果。有没有办法使用getPattern或其他方式来做到这一点?

我的代码如下:

 pjs.config({ 
    // options: 'stdout', 'file' (set in config.logFile) or 'none'
    log: 'stdout',
    // options: 'json' or 'csv'
    format: 'json',
    // options: 'stdout' or 'file' (set in config.outFile)
    //writer: 'stdout',
    writer: 'file',
    outFile: 'C:\\pjscrape\\pjscrape_out.txt'
});
pjs.addSuite({
    url: 'http://localhost:8080/multivu.portal.htm',
    scraper: function() {
        return [
           _pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(2)'),
           _pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(4)'),
           _pjs.getText('div#customerInfo table tr:nth-child(1) td:nth-child(7) img.attributes.src')
        ];
    }
}); 

1 个答案:

答案 0 :(得分:0)

我使用了jQuery,它似乎正在工作!我使用这个:$(“div#customerInfo table tr:nth-​​child(1)td:nth-​​child(7)img”)。attr(“src”)

相关问题