Skip to content

Instantly share code, notes, and snippets.

@multimeric
Last active October 10, 2019 03:07
Show Gist options
  • Save multimeric/d107df03eaca1c3e39d2ad229abddc81 to your computer and use it in GitHub Desktop.
Save multimeric/d107df03eaca1c3e39d2ad229abddc81 to your computer and use it in GitHub Desktop.
PollUnit Scraping
/**
* Scrapes the names and summary results of a PollUnit poll, without paying for the business subscription
* How to use:
* 1. Copy the entire contents of this file
* 2. Browse to the public or admin link for your poll
* 3. Open the developer tools using F12 (on Chrome)
* 4. Paste this script into the input box and press enter
* 5. Copy the text that is output
* 6. Paste it into Excel or whatever application you are using this for. If Excel asks for a delimiter, specify the tab character
**/
(() =>{
// Scrape the names of each option
const opt = Array.from(document.querySelectorAll('.option'))
// Scrape the results, and combine them with the names
const results = Array.from(document.querySelectorAll('.voteRatingStr')).map((o, i) => [opt[i].innerText, ...o.innerText.split(',').map(cell => cell.trim())]);
// Print out the table as a CSV
const csv = results.map(row => row.join('\t')).join('\n')
console.log(csv)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment