Home>

I want to use the scraped value using nightmareJS for further processing, but I'm not sure how to receive it. Specifically, I want to type the scraped value into the web input location.

var Nightmare = require ('nightmare');
var nightmare = Nightmare ();
Promise.resolve (
nightmare.
goto ('https://www.yodobashi.com/product/100000001002780005/').
wait ('. productPrice.fs16.alignM').
evaluate (() =>(return document.querySelector ('. productPrice.fs16.alignM'). innerText;})).
then ((result) =>(console.log (result);}).
catch (console.error);
nightmare.end ();

Because it cannot be connected with type after the then method (then ((result) =>(tyep ('●', result);}). cannot be used)
After that, I write a one-line type, but I can't accept it unless it is then,
What should I do now? ?

↓ There is an error in the answer

  • Answer # 1

    I modified the content in response to comments.
    How about this?

    var Nightmare = require ('nightmare');
    var nightmare = Nightmare ();
    nightmare
      .goto ('https://www.yodobashi.com/product/100000001002780005/')
      .wait ('. productPrice.fs16.alignM')
      .evaluate (() =>{
        const value = document.querySelector ('. productPrice.fs16.alignM'). innerText;
        const element = document.querySelector (/ * Selector for which you want to set the value * /);
        element.value = value;
        return value;/* What you want to pass to the result of then. Anything * /
      })
      .end ()
      .then ((result) =>{
        // Write what you want to do with the results
        // No operations within the scraping page can be done here
        console.log (result);
      })
      .catch (console.error);

Related articles