raena-crawler-engine/hasaki_crawler_engine/test.py

28 lines
707 B
Python
Raw Normal View History

2024-03-15 07:02:44 +00:00
2024-03-14 05:16:59 +00:00
from playwright.sync_api import sync_playwright
2024-03-15 07:02:44 +00:00
from fake_useragent import UserAgent
import logging
2024-03-14 05:16:59 +00:00
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
2024-03-15 07:02:44 +00:00
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)
2024-03-14 05:16:59 +00:00
page = context.new_page()
2024-03-15 07:02:44 +00:00
page.goto("https://hasaki.vn/san-pham/kem-duong-skin1004-lam-diu-da-chiet-xuat-rau-ma-75ml-89637.html")
2024-03-14 05:16:59 +00:00
2024-03-15 07:02:44 +00:00
page.reload()
2024-03-14 05:16:59 +00:00
with page.expect_response("**/wap/v2/product/detail**") as response:
2024-03-15 07:02:44 +00:00
api_requests = response.value.json()
2024-03-14 05:16:59 +00:00
browser.close()
2024-03-15 07:02:44 +00:00
print(api_requests)