dhatt
dhatt

Reputation: 41

How scrape data from table with CasperJS and PhantomJS

I am trying to scrape some data for personal use. Here's my code for CasperJS:

    var casper = require('casper').create({
    verbose: true,
    logLevel: 'debug', //debug, info, warning, error
    pageSettings: {
        loadImages: false,
        loadPlugins: false,
        userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
    },
    clientScripts: ["vendor/jquery-3.1.0.js", "vendor/lodash.js"]
   });

var fs = require('fs');
var url = 'http://24score.com/football/england/premier_league/2015-2016/regular_season/averages/';

var content = [];

function getContent() {
    var content = $(x('//*[@id="total2.5"]/table/tbody[1]/tr[1]/td[1]'));
    return _.map(content, function(e) {
        return e.innerHTML;
    })
}

casper.start(url, function() {

});

casper.then(function() {
    content = this.evaluate(getContent);
});

casper.run(function() {
    this.echo(content).exit();
});

It seems, that I have a problem with HTML element identification, I use here XPath, and nothing work. But when I choose some other element it gives me some output.

Upvotes: 2

Views: 544

Answers (1)

dhatt
dhatt

Reputation: 41

Fixed:

__utils__.getElementsByXPath('//*[@id="total2.5"]/table/tbody[1]/tr[1]/td[1]')

Upvotes: 2

Related Questions