currently trying to scrape data from another website and display it as HTML.
managed to web scrape successfully but having issues displaying as html.
i understand this is node js backend and what im attempting to do it front end , but is there a way around this??
import puppeteer from "puppeteer";
const getQuotes = async () => {
// Start a Puppeteer session with:
// - a visible browser (`headless: false` - easier to debug because you'll see the browser in action)
// - no default viewport (`defaultViewport: null` - website page will in full width and height)
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
});
// Open a new page
const page = await browser.newPage();
// On this new page:
// - open the "http://quotes.toscrape.com/" website
// - wait until the dom content is loaded (HTML is ready)
await page.goto('website', {waitUntil: 'networkidle0'});
await page.waitForSelector("#content");
// Get page data
const quotes = await page.evaluate(() => {
// Fetch the first element with class "quote"
const quote = document.querySelector(".b-offer-join");
// Fetch the sub-elements from the previously fetched quote element
// Get the displayed text and return it (`.innerText`)
const text = quote.querySelector(".b-btn-text__small").innerText;
return { text };
});
// Display the quotes
console.log(quotes);
// Close the browser
await browser.close();
};
// Start the scraping
getQuotes();
New contributor
dan297 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.