[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

calback returning null values

wasiu razak

12/18/2015 6:44:00 PM

hi am using the x ray library to scrapper a website ,with crawling feature using callback mechanism , but calling it without obj.moreDetail return values as expected

var Xray = require('..');
var x = Xray();


var html = 'http://www.myjoyonline.com/news...

function getter(url ,callback) {
setTimeout(function() {
x(url, ['div.side1 div.storypane p'])(function(err, obj) {
callback(obj);
});
}, 500);
}

x(html, 'ul.opinion-listings li', [{
title: '.head .title a',
desc: '.info',
date: '.head',
img: '.image-inner a img@src',
url: '.head .title a@href'
// fullStory: x('.head .title a@href', ['div.side1 div.storypane p']),
}])(function(err, obj) {
for (var i = 0; i < obj.length; i++) {
console.log(obj[i]);
getter(obj[i].url,function(results) {
var fullStory= results;
obj[i].moreDetails = fullStory;
console.log(obj[i]);
});
}

});

return null values only


1 Answer

Evertjan.

12/18/2015 7:55:00 PM

0

wasiu razak <razakwasiu@gmail.com> wrote on 18 Dec 2015 in
comp.lang.javascript:

> hi am using the x ray library

This NG is not a helpdesk for libraries.

Why do you need a library for this anyway?

It won't help you circumventing
the same origin security feature
of modern browsers.

Better try uitside a browser,
like with cscript/wscript or serverside jscript:

function getUrl(url) {
var http = new ActiveXObject("MSXML2.ServerXMLHTTP");
http.open("GET",url,false);
http.setRequestHeader("User-Agent", "Mozilla/5.0");
http.send();
return http.responseText;
};


> to scrapper a website ,with crawling
> feature using callback mechanism , but calling it without obj.moreDetail
> return values as expected
>
> var Xray = require('..');
> var x = Xray();
>
>
> var html = 'http://www.myjoyonline.com/news...
>
> function getter(url ,callback) {
> setTimeout(function() {
> x(url, ['div.side1 div.storypane p'])(function(err, obj) {
> callback(obj);
> });
> }, 500);
>}
>
> x(html, 'ul.opinion-listings li', [{
> title: '.head .title a',
> desc: '.info',
> date: '.head',
> img: '.image-inner a img@src',
> url: '.head .title a@href'
> // fullStory: x('.head .title a@href', ['div.side1
> div.storypane p']),
>}])(function(err, obj) {
> for (var i = 0; i < obj.length; i++) {
> console.log(obj[i]);
> getter(obj[i].url,function(results) {
> var fullStory= results;
> obj[i].moreDetails = fullStory;
> console.log(obj[i]);
> });
> }
>
>});
>
> return null values only
>
>
>



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)