Skip to content

Instantly share code, notes, and snippets.

@crevulus
Created March 4, 2021 11:31
Show Gist options
  • Save crevulus/96b403f8d7363e5eb9e3c5b1b0a72d05 to your computer and use it in GitHub Desktop.
Save crevulus/96b403f8d7363e5eb9e3c5b1b0a72d05 to your computer and use it in GitHub Desktop.
A small script using puppeteer to grab select profile data from any GitHub profile.
const puppeteer = require("puppeteer");
const crevulus = {};
async function getProfile(username) {
const browser = await puppeteer.launch({
// headless: false,
defaultViewport: null,
});
const page = await browser.newPage();
const url = `https://github.com/${username}`;
await page.goto(url);
await page.waitForSelector(".pinned-item-list-item");
const results = await page.$eval(
'div[itemtype="http://schema.org/Person"] .clearfix',
(element) => {
const image = element.querySelector(".position-relative a img").src;
const name = element.querySelector(
".vcard-names-container h1 .vcard-fullname"
).innerText;
return { name, image };
}
);
return results;
}
async function getPinned(username) {
const browser = await puppeteer.launch({
// headless: false,
defaultViewport: null,
});
const page = await browser.newPage();
const url = `https://github.com/${username}`;
await page.goto(url);
await page.waitForSelector(".pinned-item-list-item");
const results = await page.$$eval(".pinned-item-list-item", (elements) => {
return elements.map((element) => {
const pinnedProperties = {};
const repoInfo = element.querySelector(
".pinned-item-list-item-content div a"
);
const repoLink = repoInfo.href;
const repoName = repoInfo.querySelector("span").innerText;
const description = element.querySelector(
".pinned-item-list-item-content p"
).innerText;
pinnedProperties.repoName = repoName;
pinnedProperties.link = repoLink;
pinnedProperties.description = description;
return pinnedProperties;
});
});
return results;
}
async function getData(username) {
crevulus.profile = await getProfile(username);
crevulus.pinned = await getPinned(username);
console.log(crevulus);
}
getData("crevulus");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment