After printing the long and the lat, I want it to print out the country name. Is there a way of using the long and lat to figure out the country and then print that out to the console at the end?
const puppeteer = require("puppeteer");
const url = "https://www.google.com/";
async function StartScraping() {
await puppeteer
.launch({
headless: false,
})
.then(async (browser) => {
const page = await browser.newPage();
await page.setViewport({
width: 1800,
height: 800,
});
page.on("response", async (response) => {
if (response.url().includes("CoordinateFile"))
{
const location = await response.text()
let intlong = location.indexOf("Coordinates:")
const longlat = location.substring(intlong +12, intlong + 44)
//split long lat here
var long = longlat.substring(0, longlat.indexOf(',') - 5);
var lat = longlat.substring(longlat.indexOf(',') +1, (longlat.indexOf(',') + 7));
console.log(`Longitude: ${long}`);
console.log(`Latitude: ${lat}`);
}
});
await page.goto(url, {
waitUntil: "load",
timeout: 0,
});
});
}
StartScraping();