import playwright from playwright.sync_api import sync_playwright from fake_useragent import UserAgent import logging with sync_playwright() as p: browser = p.chromium.launch(headless=False, args=[ "--disable-dev-shm-usage", "--disable-blink-features=AutomationControlled", "--disable-component-extensions-with-background-pages" ]) ua = UserAgent(platforms='mobile') random_mobile_ua = ua.random logging.info("using user agent: {}".format(random_mobile_ua)) context = browser.new_context(user_agent=random_mobile_ua) context.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") page = context.new_page() try: page.goto("https://hasaki.vn/san-pham/kem-duong-skin1004-lam-diu-da-chiet-xuat-rau-ma-75ml-89637.html", timeout=5000) with page.expect_response("**/wap/v2/product/detail**") as response: api_requests = response.value.json() except playwright._impl._errors.TimeoutError: logging.info("Timeout occurred. Retrying.....") page.reload() with page.expect_response("**/wap/v2/product/detail**") as response: api_requests = response.value.json() browser.close() print(api_requests)