is it possible that a return value is guaranteed?
because if one "find" doesn not find anything the whole data is empty
so I tried this code but it only returns the first value??
const osmosis = require('osmosis');
let savedData = [];
var objSite = osmosis.get('https://www.wallstreet-online.de/etf/a0rpwh-ishares-core-msci-world-ucits-etf');
objSite.find("//*[@class='marketchange'][1]/div[1]/div[1]/div[1]/span")
.set({'kurs': 'text()'})
.data(data => {
console.log("data1:" + data);
savedData.push(data);
objSite.find("//*[@class='marketchange'][1]/div[1]/div[3]/span")
.set({'perc': 'text()'})
.data(data => {
console.log("data2:" + data);
savedData.push(data);
})
.done(function() {
var strFileData = JSON.stringify( savedData, null, 4);
console.log("strFileData:" + strFileData);
fs.writeFile('data.json', strFileData, function(err) {
if(err) console.error(err);
else console.log('Data Saved to data.json file');
})
});
});
=> output
strFileData:[
{
"kurs": "71,39"
}
]
original example which works if all xpath queries find something
objSite.find("//*[@class='marketchange'][1]/div[1]/div[1]/div[1]/span")
.set({'kurs': 'text()'})
.find("//*[@class='marketchange'][1]/div[1]/div[3]/span")
.set({'perc': 'text()'})
.data(data => {
console.log("data2:" + data);
savedData.push(data);
})
.done(function() {
var strFileData = JSON.stringify( savedData, null, 4);
console.log("strFileData:" + strFileData);
fs.writeFile('data.json', strFileData, function(err) {
if(err) console.error(err);
else console.log('Data Saved to data.json file');
})
});
=> output
strFileData:[
{
"kurs": "71,39",
"perc": "+0,08"
}
]
is it possible that a return value is guaranteed?
because if one "find" doesn not find anything the whole data is empty
so I tried this code but it only returns the first value??
=> output
strFileData:[
{
"kurs": "71,39"
}
]
original example which works if all xpath queries find something
=> output
strFileData:[
{
"kurs": "71,39",
"perc": "+0,08"
}
]