use phantomjs to crawl html file got ReferenceError: Can't find variable: NS_AdDivs

733 views
Skip to first unread message

kww

unread,
Feb 20, 2015, 11:46:40 AM2/20/15
to phan...@googlegroups.com

var page = require('webpage').create();
var fs = require('fs');
var system = require('system');

var i = system.args[1];

page.open(u1+i, function(status){
console.log("status: " + status + " " + i);
if(status === "success"){
fs.write('macrumors_'+i+'.html', page.content, 'w');
}
phantom.exit();
});
I save it as appleforum.js. Then I wrote a simple sh which I named as appleforum.sh
#!/bin/bash

for i in {12532..20000};
do
phantomjs appleforum.js $i
done

Then I ran in my mac terminal (Yosemite OS):
sh appleforum.sh

Then I got basically like this (the following is just a section of the returning things, basically they all look alike the following)

status: success 13134

ReferenceError: Can't find variable: NS_AdDivs


  http://forums.macrumors.com/showthread.php?t=13135:5666 in global code

ReferenceError: Can't find variable: NS_AdDivs


  http://forums.macrumors.com/showthread.php?t=13135:5666 in global code

status: success 13135
status: success 13136


I have googled but could not find any similar problems. I installed the phantomjs through brew. Its version is 2.0.0. I am quite new to phantomjs. Any ideas or explainations would be greatly appreciated. Thanks.

PhP

unread,
Feb 20, 2015, 2:24:46 PM2/20/15
to phan...@googlegroups.com


It may be something specific to those pages you are loading.  Your scripts are OK and should run fine.  As a matter of fact, your pages get downloaded and saved to files.  So, if you want, you can safely ignore the errors like this so you won't get those error messages:


 page.onError = function(message, trace) {
  console.log('error/2 ' + message);
  // usually, you would exit but you can ignore it here
  // phantom.exit(0);
};



 

George Booth

unread,
Mar 1, 2015, 11:00:24 AM3/1/15
to phan...@googlegroups.com
to confirm:

You installed Phantomjs 2.0 onto Yosemite via Brew

Is this running through Javascript for Automation, or via some other engine?

Kaiwei Wang

unread,
Mar 1, 2015, 3:30:43 PM3/1/15
to phan...@googlegroups.com
I installed Phantomjs 2.0 onto Yosemite via Brew. I just input phantomjs  filename.js in my terminal.

--
You received this message because you are subscribed to a topic in the Google Groups "phantomjs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phantomjs/NgRUVlm3zM8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phantomjs+...@googlegroups.com.
Visit this group at http://groups.google.com/group/phantomjs.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages