33 lines
1022 B
Python
33 lines
1022 B
Python
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)
|
|
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)
|
|
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)
|