From 7dabfa451931bcaf88a1c3107da0a3fed0741a02 Mon Sep 17 00:00:00 2001 From: zhilv Date: Fri, 28 Nov 2025 22:43:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(spider):=20=E6=96=B0=E5=A2=9E=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E4=BD=9C=E4=B8=9A=E6=96=87=E4=BB=B6:=20=E7=99=BE?= =?UTF-8?q?=E5=BA=A6=E7=BF=BB=E8=AF=91=E3=80=81TPShop=20=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Spider/README.md | 4 +++- Spider/test2.py | 26 ++++++++++++++++++++++++++ Spider/test3.py | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Spider/test2.py create mode 100644 Spider/test3.py diff --git a/Spider/README.md b/Spider/README.md index 34d4d11..b6a1354 100644 --- a/Spider/README.md +++ b/Spider/README.md @@ -11,5 +11,7 @@ ```sh . -└── test1.py # 获取研招网数据 +├── test1.py # 获取研招网数据 +├── test2.py # 使用 selenium 对 '人生苦短,我用Python' 进行翻译 +└── test3.py # 使用 selenium 对 hmshop-test.itheima.net 网站进行登录 ``` diff --git a/Spider/test2.py b/Spider/test2.py new file mode 100644 index 0000000..415c8dc --- /dev/null +++ b/Spider/test2.py @@ -0,0 +1,26 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + + +class BaiduFanYi: + def __init__(self) -> None: + self.driver = webdriver.Chrome() + + def __exit__(self): + self.driver.close() + + def run(self): + keywords = "人生苦短,我用Python" + self.driver.get("https://fanyi.baidu.com/") + text_box = self.driver.find_element(By.XPATH, '//div[@class="vQKJC1p2"]/div') + text_box.send_keys(keywords) + time.sleep(5) + output_box = self.driver.find_element( + By.XPATH, '//div[@class="_KOa3V5y XBO6S8ks"]' + ) + print("{} 翻译后: {}".format(keywords, output_box.text)) + + +if __name__ == "__main__": + BaiduFanYi().run() diff --git a/Spider/test3.py b/Spider/test3.py new file mode 100644 index 0000000..2f31c9e --- /dev/null +++ b/Spider/test3.py @@ -0,0 +1,39 @@ +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()