I am trying to make a script that will compile statistics of my TikTok profile on my WordPress site. TikTok ironically sucks at giving you data about your profile, in my case I can't find a reliable way to check the total views I have on my profile from the native analytics page.
So I figured I would write a script that would take my TikTok page, scan through the html, find each page element that displays the view count on each post thumbnail, and add the value within that element to an array. The write a function that takes care of the math from there.
I thought that would be fairly easy, but I am a victim of the Dunning-Kruger effect as a freshman in Software Engineering.
From what I've looked at the answer seems to lay in jQuery. I have written this so far.
var views= []
jQuery.get("https://www.tiktok.com/@triplicata.html",function() {
//the view count element seems to change on different occasions but the element seems to always be "== $0"
jQuery.each("$0",function(){
var temp = jQuery.text();
views.push(temp);
});
});
When I try to run it in a tester I check the F12 Console and it says something around the lines of:
Access to XMLHttpRequest at 'https://www.tiktok.com/@triplicata.html' from origin 'https://fiddle.jshell.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I can't even test the rest of the code cause I seem to be cut off at the gate just trying to get the HTML in the first place. I don't really know much about jQuery but everything seems to be correct from what I've seen.
I don't know why you would do this, ever heard of viewsource?
<script src="https://cdn.jsdelivr.net/gh/Parking-Master/viewsource/vs.js"></script>
<script>
console.log(getSource('https://example.com'));
</script>
You can't access another website's source code for a good reason. And the jquery get() method is only for JSON files.