1

How do I get the HTML array back in .then(function(document){}),

all code:

const phantom = require('phantom');
(async function() {
    const instance = await phantom.create();
    const page = await instance.createPage();

    const status = await page.open('https://lasgsfgdf.com/').then(function (status) {
        if(status == 'success') {
            page.evaluate(function() {
                return document.querySelectorAll('.resourceList > .resourceListItem');
            }).then(function(document){
                console.log(document[0].innerHTML);
            });
        }
    });

    await page.close();
    await instance.exit();
})();

Works only when the string is returned.

page.evaluate(function() {
    return document.querySelectorAll('.resourceList > .resourceListItem')[0].innerHTML;
}).then(function(document){
    console.log(document);
});

I need so that I can process the array, already in then, since in .evaluate(function() { работает только return, no idea why so.

Battle Bot
  • 11
  • 2
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Liam Feb 18 '19 at 14:56
  • You can try wrapping your async function in a promise then using `resolve (document[0].innerHTML);` to resolve it – Jonathan Feb 18 '19 at 15:06
  • Something like this? ` https://pastebin.com/NbAvu7D2 ` – Battle Bot Feb 18 '19 at 16:33

0 Answers0