how to scrape data with loop on element puppeteer

Viewed 183

So, the question is little bit tricky I want to get data with with name of the month and in between I need to fetch disabled text and without disabled. there is li with dates in particular month.

Currently i am doing like this.

const browser = await puppeteer.launch(launchOptions);
  const page = await browser.newPage();
  await page.emulate(device);
  await page.goto(
    "https://www.independentcottages.co.uk/highland/craigview-ref3417#full-calendar"
  );

  await page.waitFor("#full_calendar");

  //  ************************************************************************
  const serpDesc = await page.evaluate(() =>
    [...document.querySelectorAll(`.month_wrapper`)].map(
      (elem) => elem.innerText
    )
  );

  let allData = [];
  for (let i = 0; i < serpDesc.length; i++) {
    let data = serpDesc[i].split("\n");
    if (data) {
      allData.push(data);
    }
  }
    let cal = [];
    for(let j= 0; j < allData.length; j++){
      let filtered = allData[j].filter(function (el) {
        return el != null && el != " ";
      });
    cal.push(filtered);
  }

I just need to scrape the calender with the help of puppeter in json format. In above Code I am able to scrape the data for full month but not in specific month which dates are disabled and which are available. And Ya rest dates are rejected.

may in this piece of code I have to write for loop for the inner dates but I have not found any way to find elements inside already looping elements.

here is the codepen link may be if you want to see the HTML CodePen HTML Link but ya you can visit the link in goto function for the better view. Thank you.

0 Answers
Related