【发布时间】:2017-08-01 07:12:21
【问题描述】:
我使用 CasperJS 从网站 http://www.u-movie.com.tw/page.php?page_type=now&portal=cinema&ver=tw 获取数据。
我想删除没有id的<p>。
所以我尝试选择根并删除它,但它会显示null is not an object
如果我不使用 jQuery,只使用 javascript,我该如何解决?
任何帮助将不胜感激。
这是我的代码:
function getMovieTime() {
this.evaluate(function () {
var time = document.querySelectorAll('ul.posts p');
time.parentNode.remove();
time = document.querySelectorAll('ul.posts');
return Array.prototype.map.call(time, function (e) {
return e.innerText;
});
});
};
我调用 getMovieTime():此代码报告 null
var movieTime = []; // global variable
casper.then(function () {
movieTime = this.evaluate(getMovieTime);
});
【问题讨论】:
-
报告了
null is not an object的哪一行? -
我更新了我的问题,我调用 getMovieTime 函数导致报告为空。
-
报告哪一行?对于
this.evaluate(function () {?打电话给this.evaluate(getMovieTime)然后在getMovieTime内部再次调用this.evaluate(function () {是没有意义的。 -
是的……还有一点,谢谢提醒。
标签: javascript phantomjs casperjs simple-html-dom