D
D
dhat2016-10-07 17:50:54
JavaScript
dhat, 2016-10-07 17:50:54

Where is the mistake? Why doesn't the same script work after copying?

The same script, with minor changes. I’ve been comparing them line by line with a magnifying glass for half an hour and I just can’t understand why one works and the other doesn’t ?? Some kind of madness ...
Working script:

page.open(url, function(status) {
  console.log('Status: ' + status);
  // Do other things here...
  var bestList = page.evaluate(function() {

    var bestElements = document.querySelectorAll(
      '#featured-books-inner .book-block-title'
    );

    var bestData = [];

    for(var i = 0; i < bestElements.length; i++) {
      bestData.push(bestElements[i].innerHTML.trim());
    }

    return bestData;
  });

  console.log('-----------------------------------');
  for (var j = 0; j < bestList.length; j++) {
    console.log((j + 1) + ' | ' + bestList[ j ]);
  };

  phantom.exit();
});

Non-working script:
page.open(url, function(status) {
  console.log('Status: ' + status);
  // Do other things here...
  var bestList = page.evaluate(function() {

    var bestElements = document.querySelectorAll(
      '#featured-books-inner .book-block-title'
    );

    var bestData = [];

    for(var i = 0; i < bestElements.length; i++) {
      bestData.push(bestElements[i].innerHTML.trim());
    }

    return bestData;
  });
  // log results
  console.log('-----------------------------------');
  for (var j = 0; j < bestList.length; j++) {
    console.log((j + 1) + ' | ' + bestList[ j ]);
  };
  // exit
  phantom.exit();
)}

WHERE IS THE ERROR???
And how conveniently and quickly to compare code in similar situations? Is there some solution like diff on Github, but convenient and fast? Yuzayu Atom.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dhat, 2016-10-07
@dhat

No, well, it's full of tryndets. I found an error.")}" instead of "})"
And now the question is - HOW TO AVOID THIS?
Do you need to be covered with a bunch of tests in which to drown for several months just to quickly find bugs with brackets?
I'm shocked)))

D
Daniil Sorokin, 2016-10-07
@DanSorokin

Did you try to debug?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question