Skip to content

Instantly share code, notes, and snippets.

@sandeepthukral
Created September 14, 2018 10:32
Show Gist options
  • Save sandeepthukral/a14ec496a418837d45a96da1bf361080 to your computer and use it in GitHub Desktop.
Save sandeepthukral/a14ec496a418837d45a96da1bf361080 to your computer and use it in GitHub Desktop.
Count numbers on a webpage using Developer Console and JS. Change the selector on line 1 and , if required, the lastChild thing on the second.

This gist works on the following page http://support.vanmoof.com/

The code is used, in this case, to count the total number of topics there are on this support page.

The basic idea is to first get the elements whose text you are interested in. https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference

The $() returns an array of Element objects https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

You can then use the methods and properties described on this page to extract the info you need https://developer.mozilla.org/en-US/docs/Web/API/Element

p = $('.btn.btn-pill')
s = 0; p.each((idx, e) => s += parseInt(e.lastChild.textContent.trim())); console.log(s)
@sandeepthukral
Copy link
Author

For getting total views (last 30 days) from Quora
Go to your profile, select answers based on 30 day views
Scroll down infinitely to load all answers

aaa = Array.from($$('a.ui_qtext_more_link')); aaa.forEach((e) => e.click())

Search in the page if there is any occurrence of (more)
If yes, open these to reveal the total views.

cc = Array.from($$('.meta_num')); s = 0; cc.forEach((c) => s = s+ parseInt(c.textContent)); console.log(s)

The only issue here is that the counts in thousands and above are displayed as 6.3k. This is returned to us as 6. Not good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment