40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from selenium import webdriver
|
|
from selenium.webdriver.common.by import By
|
|
import time
|
|
|
|
|
|
class TPShop:
|
|
def __init__(self, phone: str, pwd: str) -> None:
|
|
self.driver = webdriver.Chrome()
|
|
self.phone = phone
|
|
self.password = pwd
|
|
|
|
def __exit__(self):
|
|
self.driver.close()
|
|
|
|
def run(self) -> None:
|
|
self.driver.get("https://hmshop-test.itheima.net/Home/Index/index.html")
|
|
login_a = self.driver.find_element(
|
|
By.XPATH, '//div[@class="fl nologin"]/a[@class="red"]'
|
|
)
|
|
login_a.click()
|
|
time.sleep(5)
|
|
|
|
username_input = self.driver.find_element(By.XPATH, '//input[@id="username"]')
|
|
username_input.send_keys(self.phone)
|
|
|
|
password_input = self.driver.find_element(By.XPATH, '//input[@id="password"]')
|
|
password_input.send_keys(self.password)
|
|
|
|
yzm_input = self.driver.find_element(By.XPATH, '//input[@id="verify_code"]')
|
|
yzm_input.send_keys("8888")
|
|
|
|
login_btn = self.driver.find_element(By.XPATH, '//a[@name="sbtbutton"]')
|
|
login_btn.click()
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
TPShop("13012345678", "123456").run()
|