#How to get a text reader for chrome code
You should get below output after saving above code and running the index.js I’m fullstack developer at Exponential, a global provider ofĪdvertising intelligence and digital media solutions to brand The CSS selector of paragraph is body > div > div > p const heroParagraph = await page.$eval("body > div > div > p", el => el.textContent)
Next, we will be targetting paragraph element displayed inside Hero element Once, you save above code and run the script again you should see text Portfolio on console. The CSS selector of element is #nav-menu > li:nth-child(1) const navListFirstItem = await page.$eval("#nav-menu > li:nth-child(1)", el => el.textContent) We will be getting the text of the first item in the navigation list i.e. Getting link text is very much similar to getting the text of the heading. To get element of heading we need to use element.textContent method const heading1 = await page.$eval("body > div > div > h1", el => el.textContent) Īfter, you put above code just below comment // rest of code goes below and execute the file using node index.js command, it should output text Hey 👋, I'm Gulshan Saini on terminal console. The selector of h1 element is "body > div > div > h1" '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',Ĭonst browser = await puppeteer.launch(options)Īwait tDefaultNavigationTimeout(0)įirst we will get the text of h1 heading which is displayed inside Hero element I will be using below code as starting point // file index.js We will be using the following test page which contains all types of HTML elements.
Let’s explore how we can scrape the inner text of headings, links, paragraphs, list, table, button, input, text area elements using puppeteer. It can be used to get the inner text of any element on the page however the approach differs slightly for the individual type of elements. Puppeteer is the NodeJs library that provides API to automate Chrome or Chromium browsers.