feat(spider): 新增两个作业文件: 百度翻译、TPShop 登录
This commit is contained in:
26
Spider/test2.py
Normal file
26
Spider/test2.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user