Untitled

mail@pastecode.io avatar
unknown
typescript
2 years ago
1.0 kB
2
Indexable
Never
import puppeteer from 'https:/deno.land/x/puppeteer@16.2.0/mod.ts';

const browser = await puppeteer.launch();
const page = await browser.newPage();

// await page.waitForSelector('.alv');

// let's just call them tweetHandle

const data: string[] = [];

for (let index = 0; index < 1001; index++) {
  await page.goto(
    `https://www.city-town.uk/country-england.html?page=${index + 1}`
  );
  const placeNames = await page.$$(".alv");

  if(!placeNames || placeNames.length === 0){
    break;
  }
  // loop thru all handles
  for (const placeName of placeNames) {
    // pass the single handle below
    const singlePlace: string = await page.evaluate((el) => el.innerText, placeName);

    if(!data.find(t => t === singlePlace.toLocaleLowerCase())){
      data.push(singlePlace.toLocaleLowerCase());
      console.log(`Page: ${index} - ${singlePlace.toLocaleLowerCase()}`);
    }
  }
}

await Deno.writeTextFile("./test.txt", data.join(", "));

// await page.screenshot({ path: "example.png" });

await browser.close();