2
const puppeteer = require ('puppeteer');

async function grabStocks(url){
    const browser = await puppeteer.launch();
    const page = await browser.newpage();
    await page.goto(url);


    const[el] = await page.$x('//*[@id="home-contents"]/table/tbody/tr[3]/td[2]')
    const src = await el.getProperty('src');
    const srcTxt = await src.jasonValue();

    console.log({srcTxt});
}



grabStocks ('http://www.nepalstock.com/todaysprice');

The error is this

> [roshan@fedora Web scraping project]$ node nepalstock.js
> internal/modules/cjs/loader.js:888   throw err;   ^
> 
> Error: Cannot find module '/home/roshan/Web scraping
> project/nepalstock.js'
>     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
>     at Function.Module._load (internal/modules/cjs/loader.js:730:27)
>     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
>     at internal/main/run_main_module.js:17:47 {   code: 'MODULE_NOT_FOUND',   requireStack: []

I had installed the puppeteer in the same folder but it is showing this error.

2
  • @Ajay2707: read the actual error Commented May 25, 2021 at 3:44
  • It seems that nepalstock.js doesn't exist Commented May 25, 2021 at 3:51

2 Answers 2

1

There may be a problem that you haven't exported your grabstocks() method. Maybe module.exports = {grabstocks} inside this file should do the trick :)

  const puppeteer = require ('puppeteer');
    async function grabStocks(url){
        const browser = await puppeteer.launch();
        const page = await browser.newpage();
        await page.goto(url);
    
    
        const[el] = await page.$x('//*[@id="home-contents"]/table/tbody/tr[3]/td[2]')
        const src = await el.getProperty('src');
        const srcTxt = await src.jasonValue();
    
        console.log({srcTxt});
    }

module.exports = {grabstocks}

and then can try to use it. But again as the error says nepalstock.js module not found maybe cuz you haven't exported any method of it that you wanna use . Just guessing :)

Sign up to request clarification or add additional context in comments.

Comments

1

I didn't init npm correctly.

npm init -y

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.