diff --git a/README.md b/README.md index 97d89488..f6964521 100644 --- a/README.md +++ b/README.md @@ -94,10 +94,6 @@ python -m examples.getTrending You can find the documentation [here](https://davidteather.github.io/TikTok-Api/docs) (you'll likely just need the TikTokApi section of the docs), I will be making this documentation more complete overtime as it's not super great right now, but better than just having it in the readme! -## Built With - -* [Python 3.7](https://www.python.org/) - The web framework used - ## Authors * **David Teather** - *Initial work* - [davidteather](https://github.com/davidteather) diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index 8989986a..9cbf83d2 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -869,10 +869,8 @@ def get_music_object_full(self, id, **kwargs): proxies=self.__format_proxy(kwargs.get("proxy", None)), cookies=self.get_cookies(**kwargs), ) - t = r.text - j_raw = t.split( - '")[0] + + j_raw = self.__extract_tag_contents(r.text) return json.loads(j_raw)["props"]["pageProps"]["musicInfo"] def by_hashtag(self, hashtag, count=30, offset=0, **kwargs) -> dict: @@ -1104,9 +1102,7 @@ def get_tiktok_by_html(self, url, **kwargs) -> dict: t = r.text try: - j_raw = t.split( - '")[0] + j_raw = self.__extract_tag_contents(r.text) except IndexError: if not t: logging.error("TikTok response is empty") @@ -1118,7 +1114,7 @@ def get_tiktok_by_html(self, url, **kwargs) -> dict: if data["serverCode"] == 404: raise TikTokNotFoundError( - "TikTok with that url doesn't exist".format(username) + "TikTok with that url doesn't exist" ) return data @@ -1206,9 +1202,7 @@ def get_user(self, username, **kwargs) -> dict: t = r.text try: - j_raw = t.split( - '")[0] + j_raw = self.__extract_tag_contents(r.text) except IndexError: if not t: logging.error("Tiktok response is empty") @@ -1563,9 +1557,7 @@ def get_music_title(self, id, **kwargs): cookies=self.get_cookies(**kwargs), ) t = r.text - j_raw = t.split( - '")[0] + j_raw = self.__extract_tag_contents(r.text) music_object = json.loads(j_raw)["props"]["pageProps"]["musicInfo"] if not music_object.get("title", None): @@ -1659,6 +1651,15 @@ def __add_new_params__(self) -> str: } return urlencode(query) + def __extract_tag_contents(self, html): + nonce_start = '
' + nonce = html.split(nonce_start)[1].split(nonce_end)[0] + j_raw = html.split( + '")[0] + return j_raw + # Process the kwargs def __process_kwargs__(self, kwargs): region = kwargs.get("region", "US")