Use specific and unique CSS selectors to accurately target the element from which you want to extract text.
When using innerText, remember it reflects the text as seen on the page, including handling styles that affect visibility, which is useful for scraping rendered text.
To extract raw text without any HTML tags, use textContent as it ignores styling and provides the content of the node and its descendants.
If you need to capture the HTML content and then remove tags, use innerHTML combined with a regular expression to strip out HTML tags, ensuring you get only the textual content.
Ensure that the page has fully loaded before attempting to extract text, as Puppeteer might try to access elements that aren't yet available on the DOM.
Handle potential null values returned from querySelector by checking if the element exists before attempting to access its properties to avoid runtime errors.
Consider using page.waitForSelector to ensure the element is present and avoid timing issues when trying to retrieve text.
Be aware of the differences between textContent, innerText, and innerHTML to choose the most appropriate method based on whether you need to consider the style or just extract raw data.
Gabija Fatenaite
2025-07-30
Yelyzaveta Hayrapetyan
2025-05-27
Adelina Kiskyte
2024-10-29
Get the latest news from data gathering world
Scale up your business with Oxylabs®
Proxies
Advanced proxy solutions
Data Collection
Datasets
Resources
Innovation hub