55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import logging
|
|
from fake_useragent import UserAgent
|
|
import brotli
|
|
import seleniumwire.undetected_chromedriver as uc
|
|
from selenium_stealth import stealth
|
|
import json
|
|
import time
|
|
|
|
def get_raw_product_data_selenium(url):
|
|
ua = UserAgent(platforms='mobile')
|
|
random_mobile_ua = ua.random
|
|
logging.info("using user agent: {}".format(random_mobile_ua))
|
|
|
|
op = uc.ChromeOptions()
|
|
op.add_argument(f"user-agent={random_mobile_ua}")
|
|
op.add_argument('--blink-settings=imagesEnabled=false')
|
|
#op.add_experimental_option("useAutomationExtension", False)
|
|
#op.add_argument('--no-sandbox')
|
|
#op.add_argument('--disable-notifications')
|
|
#op.add_argument("--lang=en-GB")
|
|
op.headless = False
|
|
|
|
driver = uc.Chrome(version_main=122, options=op)
|
|
stealth(driver,
|
|
languages=["en-US", "en"],
|
|
vendor="Google Inc.",
|
|
platform="Win32",
|
|
webgl_vendor="Intel Inc.",
|
|
renderer="Intel Iris OpenGL Engine",
|
|
fix_hairline=True
|
|
)
|
|
|
|
driver.get(url)
|
|
|
|
time.sleep(100)
|
|
|
|
iteminfo = ""
|
|
|
|
for request in driver.requests:
|
|
if request.response:
|
|
if '/wap/v2/product/detail' in request.url:
|
|
encoding = request.response.headers.get('content-encoding')
|
|
# logging.info(encoding)
|
|
if encoding:
|
|
iteminfo = brotli.decompress(request.response.body)
|
|
else:
|
|
iteminfo = request.response.body
|
|
|
|
driver.quit()
|
|
|
|
iteminfo_json = json.loads(iteminfo)
|
|
print(iteminfo_json)
|
|
|
|
|
|
get_raw_product_data_selenium('https://hasaki.vn/san-pham/tinh-chat-chong-nang-sunplay-hieu-chinh-sac-da-50g-xanh-87613.html') |