Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't scrape contributors div from github insights page

I am trying to scrape github contributor insights using NodeJS, puppeteer, and cheerio.

const cheerio = require('cheerio');
const puppeteer = require('puppeteer');
const url = 'https://github.com/grey-software/grey.software/graphs/contributors';

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.waitForSelector('#contributors', {
    visible: true,
  })

  await page.goto(url);
  const pageContent = await page.content()

  const $ = cheerio.load(pageContent);
  $('.contrib-person').each(function (i, elem) {
    console.log(elem)
  });
  await browser.close();
})();

I get the following error when I run the code above

UnhandledPromiseRejectionWarning: TimeoutError: waiting for selector "#contributors" failed: timeout 30000ms exceeded

The #contributors div should load within the 30 seconds, but I always get this timeout. Note: page.waitForNavigation() gives the same timeout error

like image 608
OsamaSaleh289 Avatar asked Nov 23 '25 10:11

OsamaSaleh289


1 Answers

Your issue is you are waiting for the selector to exist... Before you go to the website in the first place. use page.waitForSelector() after you use page.goto()

like image 181
destroyer22719 Avatar answered Nov 24 '25 23:11

destroyer22719



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!