casperJS를 처음 사용합니다. Windows 8에 casperJS 1.0.4 및 phantomJS 1.8.2를 설치했습니다.CasperJS 1.0.4 - this.getElementsInfo() 오류가 발생했습니다.
내 목표는 그물에서 일부 데이터를 긁는 것입니다. 이 webpage을 열고 버몬트에있는 마을의 목록을 가져오고 싶습니다. 나는 Victor W Yee에 의해 주어진 코드를 복제했다.
var town_names_info = this.getElementsInfo(town_selector);
오류는 말한다 : 내가 코드를 실행하면 내가 검증으로의 스냅 샷을하지만 난 테이블에서 데이터를 시도하고 가져올 때이 줄에 오류가 발생, 원하는 페이지를 엽니 다
TypeError: 'undefined' is not a function(evaluating'this.getElementsInfo(town_selector)')
F:/Trial Codes/intro to casper_JS/Vermont/vermont.js:21
F:/Trial Codes/intro to casper_JS/Vermont:1335 in runStep
F:/Trial Codes/intro to casper_JS/Vermont:332 in checkStep
의견이 있으십니까 ??
내 전체 코드는 다음과 같습니다
var utils = require('utils');
var casper = require('casper').create({
verbose: false,
logLevel: 'debug'
});
var url = 'http://en.wikipedia.org/wiki/List_of_towns_in_Vermont';
var town_selector;
casper.start(url, function() {
this.capture("result1.png");
this.echo("* "+this.getTitle()+" *");
});
casper.then(function() {
// Get info on all elements matching this CSS selector
town_selector = 'table[id="sortable wikitable"] tbody tr td:nth-of-type(2)';
var town_names_info = this.getElementsInfo(town_selector); // an array of object literals
// Pull out the town name text and push into the town_names array
var town_names = [];
for (var i = 0; i < town_names_info.length; i++)
{
town_names.push(town_names_info[i].text);
}
// Dump the town_names array to screen
utils.dump(town_names);
});
casper.run(function() {
this.exit();
});