I was trying to practice data scraping for our project and I can successfully see the data if I enter node scrapers.js. However, when I load it into a livecount.html file, there's an error showing and I can't display the data collected from data scraping.
The error is: "was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)"
Here's the code from the html file
<html lang="en"> <head> </head> <body> Total cases: <span id="totalCases"></span> <br> Recovered cases: <span id="recovered"></span> <br> <script src="scrapers.js" type="text/html"> </script> </body> </html>
and here's the code from scrapers.js
const puppeteer = require('puppeteer');
async function scrapeProduct(url){ const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto(url); const [el] = await page.$x('//*[@id="yDmH0d"]/c-wiz/div/div[2]/div[2]/div[4]/div/div/div[2]/div/div[1]/table/tbody/tr[2]/td[1]'); const txt = await el.getProperty('textContent'); const rawTxt = await txt.jsonValue(); console.log(rawTxt); const [el2] = await page.$x('//*[@id="yDmH0d"]/c-wiz/div/div[2]/div[2]/div[4]/div/div/div[1]/div[1]/div/div/div[2]/div[2]'); const txt2 = await el2.getProperty('textContent'); const recovered = await txt2.jsonValue(); console.log(recovered); browser.close(); document.write("total cases: " + rawTxt + "\n" + "recovered: " + recovered); } scrapeProduct('https://news.google.com/covid19/map?hl=en-PH&gl=PH&ceid=PH%3Aen&mid=%2Fm%2F05v8c');
I'm just new to these things so I don't really know how things works, just practicing stuff for our website project, and I wanted to display data to our website from another website. Any opinions will help! Thank you
Aucun commentaire:
Enregistrer un commentaire