프로그래밍/Python

파이썬 selenium 타오바오 로그인하기

abfc 2021. 7. 28.
반응형

selenium으로 타오바오 로그인하기

 

 

 

 

파이썬 selenium을 이용해 타오바오에 로그인하는 방법입니다.

 

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from fake_useragent import UserAgent
import time

options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
user_ag = UserAgent().random
options.add_argument('user-agent=%s'%user_ag)
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("prefs", {"prfile.managed_default_content_setting.images": 2})
driver = webdriver.Chrome('chromedriver.exe', options=options)

# 크롤링 방지 설정을 undefined로 변경
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """
            Object.defineProperty(navigator, 'webdriver', {
                get: () => undefined
            })
            """
})

wait = WebDriverWait(driver, 5)

url = 'https://login.taobao.com/member/login.jhtml'
driver.get(url=url)
time.sleep(2)

id_input = wait.until(EC.presence_of_element_located((By.ID, "fm-login-id")))
id_input.send_keys('타오바오아이디')

pw_input = wait.until(EC.presence_of_element_located((By.ID, "fm-login-password")))
pw_input.send_keys('타오바오패스워드')

wait.until(EC.presence_of_element_located((By.CLASS_NAME, "fm-button"))).click()

 

 

 

 

공감과 댓글은 작성자에게 많은 힘이됩니다. 감사합니다😄

 

 

 

 

 

 

 

 

 

반응형

댓글

💲 추천 글