0

I m scraping soccer scores data from website. All scores are in a table, every <tr> has "block home matches 17" and some unique stuff after it.

I tested my xpath in the Chrome dev tools, it recognizes only the table rows I need.

var utils = require('utils');
var casper = require('casper').create();
var xpath = require('casper').selectXPath;
var result = [];

function getScores(){
    console.log("getting scores");
    result = __utils__.getElementsByXPath("//tr[contains(@id,'block_home_matches_17')");
}

casper.start('http://int.soccerway.com/', function() {
    console.log("casper start....");       
    var l = getScores();
    utils.dump(l);
});

casper.run();

The code returns [] as utils.dump! Why? my xpath is valid!

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
ERJAN
  • 23,696
  • 23
  • 72
  • 146
  • Related? http://stackoverflow.com/questions/3655549/xpath-containstext-some-string-doesnt-work-when-used-with-node-with-more – Marvin Smit Jan 03 '16 at 16:25

1 Answers1

4

You have three problems:

You can retrieve a representation of your targeted DOM nodes either through CasperJS functions:

casper.start('http://int.soccerway.com/', function() {
    utils.dump(this.getElementsInfo(xpath("//tr[contains(@id,'block_home_matches_17')")));
});

or by directly working on the elements in the page context:

casper.start('http://int.soccerway.com/', function() {
    utils.dump(this.evaluate(function(){
        return __utils__.getElementsByXPath("//tr[contains(@id,'block_home_matches_17')").map(function(el){
            return {} // TODO: produce your own representation
        });
    }));
});
Artjom B.
  • 61,146
  • 24
  • 125
  • 222