Created
September 6, 2021 14:06
-
-
Save linkfy/e0170acf2964a3dab74da29a30eb030d to your computer and use it in GitHub Desktop.
Tiktok Analytics Json with Python
This file contains 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
import requests | |
import json | |
from bs4 import BeautifulSoup | |
userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" | |
session = requests.Session() | |
baseUrl = "https://www.tiktok.com/" | |
profile = "linkfydev" | |
url = baseUrl+"@"+profile | |
r = session.get(url, headers={'User-Agent': userAgent}) | |
html = r.text; | |
scriptId = "__NEXT_DATA__" | |
soup = BeautifulSoup(html, 'html.parser') | |
script = str(soup.find("script", {"id": scriptId })) | |
script = script.split(">")[1] | |
script = script.split("<")[0] | |
#El Json | |
elJson = json.loads(script) | |
print(elJson) | |
exit() | |
##EXTRAS################### | |
url = "https://www.tiktok.com/node/share/video/@linkfydev/7003298855315918085" | |
r = session.get(url, headers = {'User-Agent': userAgent}) | |
data = r.json() | |
referer = data['seoProps']['metaParams']['canonicalHref'] | |
videoUrl = data['itemInfo']['itemStruct']['video']['downloadAddr'] | |
r = session.get(videoUrl, | |
headers= {'User-Agent' : userAgent, 'Referer':referer}) | |
print(videoUrl) | |
with open('tiktok.mp4', 'wb') as file: | |
file.write(r.content) | |
print(referer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment