74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
def get_html_selenium(url, referer):
|
|
from selenium.webdriver.common.by import By
|
|
from selenium import webdriver
|
|
from selenium_stealth import stealth
|
|
from webdriver_manager.chrome import ChromeDriverManager
|
|
import time
|
|
import platform
|
|
import os
|
|
|
|
os_platform = platform.system()
|
|
|
|
options = webdriver.ChromeOptions()
|
|
# 크롬드라이버 헤더 옵션추가 (리눅스에서 실행시 필수)
|
|
options.add_argument("start-maximized")
|
|
# options.add_argument("--headless")
|
|
options.add_argument("--no-sandbox")
|
|
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
|
options.add_experimental_option("useAutomationExtension", False)
|
|
|
|
if os_platform == "Darwin":
|
|
# 크롬드라이버 경로
|
|
driver_path = "./bin/Darwin/chromedriver"
|
|
# driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
|
|
driver = webdriver.Chrome(
|
|
ChromeDriverManager().install(), chrome_options=options
|
|
)
|
|
else:
|
|
driver_bin_path = os.path.join(
|
|
os.path.dirname(__file__), "bin", f"{os_platform}"
|
|
)
|
|
driver_path = f"{driver_bin_path}/chromedriver"
|
|
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
|
|
|
|
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)
|
|
|
|
driver.refresh()
|
|
print(f"current_url:: {driver.current_url}")
|
|
# logger.debug(f"current_cookie:: {driver.get_cookies()}")
|
|
cookies_list = driver.get_cookies()
|
|
|
|
cookies_dict = {}
|
|
for cookie in cookies_list:
|
|
cookies_dict[cookie["name"]] = cookie["value"]
|
|
|
|
print(cookies_dict)
|
|
|
|
# LogicAniLife.cookies = cookies_list
|
|
# # LogicAniLife.headers["Cookie"] = driver.get_cookies()
|
|
# LogicAniLife.episode_url = driver.current_url
|
|
|
|
time.sleep(1)
|
|
elem = driver.find_element(By.XPATH, "//*")
|
|
source_code = elem.get_attribute("outerHTML")
|
|
|
|
li_elem = driver.find_element(By.XPATH, "//li[@class='-qHwcFXhj0']//a")
|
|
li_elem.click()
|
|
|
|
time.sleep(20.0)
|
|
|
|
return source_code.encode("utf-8")
|
|
|
|
|
|
url = "https://smartstore.naver.com/flamingo_k"
|
|
get_html_selenium(url=url, referer=None)
|