Skip to content

Instantly share code, notes, and snippets.

@manabusakai
Last active January 4, 2023 03:04
Show Gist options
  • Save manabusakai/e011fde4597c2ea8ca3884c888ea48ff to your computer and use it in GitHub Desktop.
Save manabusakai/e011fde4597c2ea8ca3884c888ea48ff to your computer and use it in GitHub Desktop.
import jsdom from "jsdom";
const { JSDOM } = jsdom;
(() => {
const virtualConsole = new jsdom.VirtualConsole();
virtualConsole.sendTo(console, {
omitJSDOMErrors: true
});
const url = process.argv[2];
const options = { virtualConsole };
JSDOM.fromURL(url, options).then(dom => {
const selector = "button.o-noteLikeV3__count";
const targetElement = dom.window.document.querySelector(selector);
let likeCount = 0;
if (targetElement !== null) {
likeCount = targetElement.textContent.match(/[0-9]+/);
}
console.log(url + "\t" + likeCount);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment