Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tiktok returned invalid reponse caused by bot detection #1197

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,15 @@ def handle_request(request):
page.set_default_navigation_timeout(timeout)

await page.goto(url)
await page.goto(url) # hack: tiktok blocks first request not sure why
await page.goto(url) # hack: tiktok blocks first request not sure why, likely bot detection

# by doing this, we are simulate scroll event using mouse to `avoid` bot detection
await page.wait_for_load_state("networkidle")
x, y = random.randint(0, 50), random.randint(0, 50)
a, b = random.randint(1, 50), random.randint(100, 200)

await page.mouse.move(x, y)
await page.mouse.move(a, b)

session = TikTokPlaywrightSession(
context,
Expand Down