Last active
January 22, 2023 10:39
-
-
Save epintos/4bea8d70c9f52a47170f8cd66ddecfa1 to your computer and use it in GitHub Desktop.
Export Medium Stats Stores to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run Inspector Console in chrome and copy and paste the following code in the /stats/stories view | |
function download(filename, text) { | |
var pom = document.createElement('a'); | |
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | |
pom.setAttribute('download', filename); | |
if (document.createEvent) { | |
var event = document.createEvent('MouseEvents'); | |
event.initEvent('click', true, true); | |
pom.dispatchEvent(event); | |
} | |
else { | |
pom.click(); | |
} | |
} | |
content = ""; | |
rows = document.querySelectorAll(".sortableTable-row.js-statsTableRow") | |
rows.forEach(function(row) { | |
title = row.querySelectorAll(".sortableTable-title > a")[0].innerText | |
values = row.querySelectorAll(".sortableTable-value") | |
views = values[1].innerText | |
reads = values[2].innerText | |
readRatio = values[3].innerText | |
recommends = values[4].innerText | |
content += title + ";" + views + ";" + reads + ";" + readRatio + ";" + recommends + "\n" | |
}); | |
download("medium-metrics-" + new Date().toISOString().slice(0, 10) + ".csv", content) |
Howdy,
Same with me I don't use Medium anymore so can't really assist, apologies.
Take care!
Thanks for the quick reply guys. I really appreciate it.
I am gonna ask a follow-up, hoping you remember the document structure:)
I see that you extract the data based on the class names with querySelectorAll(), and then, parse them. But, I could not find the div where the list of daily counts is stored. Is my assumption correct? Was it stored under a single div within the main document object?
Hey @ogyalcin, I am sorry but I can't remember the HTML structure. It looks that I am doing exactly that in the script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @ogyalcin. I'm sorry but I don't have access to the account I was using anymore. I am not sure if the HTML and CSS changed, but if you use the Chrome Dev Inspector you might be able to fix it with a few modifications :)