Skip to content

Commit

Permalink
Added an option to disable image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
YudinV committed Aug 20, 2023
1 parent 81bb842 commit 8973d1c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ async def __create_session(
context_options: dict = {},
sleep_after: int = 1,
cookies: dict = None,
load_images: bool = True,
):
"""Create a TikTokPlaywrightSession"""
if ms_token is not None:
Expand All @@ -168,6 +169,10 @@ def handle_request(request):
request_headers = request.headers

page.once("request", handle_request)

if not load_images:
await page.route("**/*", lambda route: route.abort() if route.request.resource_type == "image" else route.continue_())

await page.goto(url)

session = TikTokPlaywrightSession(
Expand Down Expand Up @@ -201,6 +206,7 @@ async def create_sessions(
context_options: dict = {},
override_browser_args: list[dict] = None,
cookies: list[dict] = None,
load_images = True,
):
"""
Create sessions for use within the TikTokApi class.
Expand All @@ -218,6 +224,7 @@ async def create_sessions(
context_options (dict): Options to pass to the playwright context.
override_browser_args (list[dict]): A list of dictionaries containing arguments to pass to the browser.
cookies (list[dict]): A list of cookies to use for the sessions, you can get these from your cookies after visiting TikTok.
load_images (bool): Whether you want the browser to load the images.
Example Usage:
.. code-block:: python
Expand All @@ -243,6 +250,7 @@ async def create_sessions(
context_options=context_options,
sleep_after=sleep_after,
cookies=random_choice(cookies),
load_images=load_images,
)
for _ in range(num_sessions)
)
Expand Down

0 comments on commit 8973d1c

Please sign in to comment.