Skip to content

Commit

Permalink
V2.1 Allows for over 68 to be fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
davidteather committed Aug 28, 2019
1 parent 59e03cc commit 21a7700
Showing 1 changed file with 53 additions and 12 deletions.
65 changes: 53 additions & 12 deletions tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def __init__(self):
proc.kill()

dict = {'port': 8090}
server = Server(path="browsermob-proxy/bin/browsermob-proxy", options=dict)
server = Server(
path="browsermob-proxy/bin/browsermob-proxy", options=dict)
server.start()
time.sleep(1)
proxy = server.create_proxy()
Expand All @@ -24,7 +25,6 @@ def __init__(self):
profile.set_proxy(selenium_proxy)
driver = webdriver.Firefox(firefox_profile=profile)


proxy.new_har("list")
driver.get("https://www.tiktok.com/en/trending")
data = proxy.har
Expand All @@ -36,11 +36,10 @@ def __init__(self):
server.stop()
driver.quit()


def trending(self, count=10, verbose=0):
import requests
loop = True
while loop is True:

while True:
url = "https://m.tiktok.com/share/item/list?id=&type=5&count=" + \
str(count) + "&minCursor=0&maxCursor=0&_signature=" + \
self.signature
Expand All @@ -49,29 +48,71 @@ def trending(self, count=10, verbose=0):
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"})

data = r.json()
response = []

if data["statusCode"] != 0:
if verbose == 1:
print("Invalid Signature Retrying")
else:
loop = False
return data["body"]["itemListData"]
for tiktok in data["body"]["itemListData"]:
response.append(tiktok)
while True:
if count > len(response) and str(data['body']['hasMore']) == "True":
url = "https://m.tiktok.com/share/item/list?id=&type=5&count=" + \
str(count - len(response)) + "&minCursor=0&maxCursor=" + \
data['body']['maxCursor'] + \
"&_signature=" + self.signature

r = requests.get(url, headers={"authority": "m.tiktok.com", "method": "GET", "path": url.split("https://m.tiktok.com")[0], "scheme": "https", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-encoding": "gzip, deflate, br", "accept-language": "en-US,en;q=0.9", "cache-control": "max-age=0", "upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"})
data = r.json()
for tiktok in data["body"]["itemListData"]:
response.append(tiktok)
else:
return response

def userPosts(self, id, count=10, verbose=0):
import requests
loop = True
while loop is True:
url = "https://m.tiktok.com/share/item/list?id=" + str(id) +"&type=1&count=" + \
while True:
url = "https://m.tiktok.com/share/item/list?id=" + str(id) + "&type=1&count=" + \
str(count) + "&minCursor=0&maxCursor=0&_signature=" + \
self.signature
r = requests.get(url, headers={"authority": "m.tiktok.com", "method": "GET", "path": url.split("https://m.tiktok.com")[0], "scheme": "https", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-encoding": "gzip, deflate, br", "accept-language": "en-US,en;q=0.9", "cache-control": "max-age=0", "upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"})

data = r.json()
response = []

if data["statusCode"] != 0:
if verbose == 1:
print("Invalid Signature Retrying")
else:
loop = False
return data["body"]["itemListData"]
for tiktok in data["body"]["itemListData"]:
response.append(tiktok)
while True:
if count > len(response) and str(data['body']['hasMore']) == "True":
url = "https://m.tiktok.com/share/item/list?id=" + str(id) + "&type=1&count=" + \
str(count - len(response)) + "&minCursor=0&maxCursor=" + data['body']['maxCursor'] + "&_signature=" + \
self.signature
var = True
while var:

r = requests.get(url, headers={"authority": "m.tiktok.com", "method": "GET", "path": url.split("https://m.tiktok.com")[0], "scheme": "https", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-encoding": "gzip, deflate, br", "accept-language": "en-US,en;q=0.9", "cache-control": "max-age=0", "upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"})

data = r.json()

if data["statusCode"] == 0:
for tiktok in data["body"]["itemListData"]:
response.append(tiktok)
var = False

else:
if verbose == 1:
print("Invalid Signature Retrying")

else:
return response

0 comments on commit 21a7700

Please sign in to comment.