Skip to content

Commit

Permalink
V4.0.0
Browse files Browse the repository at this point in the history
V4.0.0 - Fixes quite a few bugs
  • Loading branch information
davidteather authored Aug 4, 2021
2 parents d4b912f + 91e6612 commit f1597cd
Show file tree
Hide file tree
Showing 45 changed files with 12,784 additions and 9,939 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ acrawl.js
test2.py
build
MANIFEST
src
src
.vscode
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py

Please don't open an issue if you're experiencing one of these just comment if the provided solution do not work for you.

* [Browser object has no attribute verifyFp](https://github.com/davidteather/TikTok-Api/issues/237) There's so many issues by this error please search (open and closed) issues before posting
* [Browser closed unexpectedly](https://github.com/davidteather/TikTok-Api/issues/95)
* [BadStatusLine](https://github.com/davidteather/TikTok-Api/issues/88)
* **Has no Attribute .width** - make sure you ran `python3 -m playwright install`, if your error persists try the [playwright](https://github.com/microsoft/playwright-python) quickstart guide and diagnose issues from there.

## Quick Start Guide

Expand Down Expand Up @@ -90,7 +88,7 @@ To run the example scripts from the repository root, make sure you use the
module form of python the interpreter

```sh
python -m examples.getTrending
python -m examples.get_trending
```

[Here's](https://gist.github.com/davidteather/7c30780bbc30772ba11ec9e0b909e99d) an example of what a tiktok dictionary looks like.
Expand Down
44 changes: 23 additions & 21 deletions TikTokApi/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ def __init__(
self,
**kwargs,
):
self.kwargs = kwargs
self.debug = kwargs.get("debug", False)
self.proxy = kwargs.get("proxy", None)
self.api_url = kwargs.get("api_url", None)
self.referrer = kwargs.get("referer", "https://www.tiktok.com/")
self.language = kwargs.get("language", "en")
self.executablePath = kwargs.get("executablePath", None)
self.did = kwargs.get("custom_did", None)
self.device_id = kwargs.get("custom_device_id", None)
find_redirect = kwargs.get("find_redirect", False)

args = kwargs.get("browser_args", [])
Expand Down Expand Up @@ -88,19 +89,20 @@ def __init__(
context.close()

def get_params(self, page) -> None:
# self.browser_language = await self.page.evaluate("""() => { return
# navigator.language || navigator.userLanguage; }""")
self.browser_language = ""
# self.timezone_name = await self.page.evaluate("""() => { return
# Intl.DateTimeFormat().resolvedOptions().timeZone; }""")
self.timezone_name = ""
# self.browser_platform = await self.page.evaluate("""() => { return window.navigator.platform; }""")
self.browser_platform = ""
# self.browser_name = await self.page.evaluate("""() => { return window.navigator.appCodeName; }""")
self.browser_name = ""
# self.browser_version = await self.page.evaluate("""() => { return window.navigator.appVersion; }""")
self.browser_version = ""
self.browser_language = self.kwargs.get("browser_language", page.evaluate("""() => { return navigator.language; }"""))
self.browser_version = page.evaluate("""() => { return window.navigator.appVersion; }""")

if len(self.browser_language.split("-")) == 0:
self.region = self.kwargs.get("region", "US")
self.language = self.kwargs.get("language", "en")
elif len(self.browser_language.split("-")) == 1:
self.region = self.kwargs.get("region", "US")
self.language = self.browser_language.split("-")[0]
else:
self.region = self.kwargs.get("region", self.browser_language.split("-")[1])
self.language = self.kwargs.get("language", self.browser_language.split("-")[0])

self.timezone_name = self.kwargs.get("timezone_name", page.evaluate("""() => { return Intl.DateTimeFormat().resolvedOptions().timeZone; }"""))
self.width = page.evaluate("""() => { return screen.width; }""")
self.height = page.evaluate("""() => { return screen.height; }""")

Expand Down Expand Up @@ -177,12 +179,12 @@ def sign_url(self, **kwargs):
"verify_khgp4f49_V12d4mRX_MdCO_4Wzt_Ar0k_z4RCQC9pUDpX",
)

if kwargs.get("custom_did") is not None:
did = kwargs.get("custom_did", None)
elif self.did is None:
did = str(random.randint(10000, 999999999))
if kwargs.get("custom_device_id") is not None:
device_id = kwargs.get("custom_device_id", None)
elif self.device_id is None:
device_id = str(random.randint(10000, 999999999))
else:
did = self.did
device_id = self.device_id

page.set_content("<script> " + get_acrawler() + " </script>")
evaluatedPage = page.evaluate(
Expand All @@ -191,8 +193,8 @@ def sign_url(self, **kwargs):
+ url
+ "&verifyFp="
+ verifyFp
+ """&did="""
+ did
+ """&device_id="""
+ device_id
+ """"
var token = window.byted_acrawler.sign({url: url});
return token;
Expand All @@ -201,7 +203,7 @@ def sign_url(self, **kwargs):
context.close()
return (
verifyFp,
did,
device_id,
evaluatedPage,
)

Expand Down
18 changes: 9 additions & 9 deletions TikTokApi/browser_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
self.referrer = kwargs.get("referer", "https://www.tiktok.com/")
self.language = kwargs.get("language", "en")
self.executablePath = kwargs.get("executablePath", "chromedriver")
self.did = kwargs.get("custom_did", None)
self.device_id = kwargs.get("custom_device_id", None)

args = kwargs.get("browser_args", [])
options = kwargs.get("browser_options", {})
Expand Down Expand Up @@ -152,24 +152,24 @@ def sign_url(self, **kwargs):
"verify_khgp4f49_V12d4mRX_MdCO_4Wzt_Ar0k_z4RCQC9pUDpX",
)

if kwargs.get("custom_did") is not None:
did = kwargs.get("custom_did", None)
elif self.did is None:
did = str(random.randint(10000, 999999999))
if kwargs.get("custom_device_id") is not None:
device_id = kwargs.get("custom_device_id", None)
elif self.device_id is None:
device_id = str(random.randint(10000, 999999999))
else:
did = self.did
device_id = self.device_id

return (
verifyFp,
did,
device_id,
self.browser.execute_script(
'''
var url = "'''
+ url
+ "&verifyFp="
+ verifyFp
+ """&did="""
+ did
+ """&device_id="""
+ device_id
+ """"
var token = window.byted_acrawler.sign({url: url});
return token;
Expand Down
Loading

0 comments on commit f1597cd

Please sign in to comment.