from selenium.webdriver import Chrome, ChromeOptions from selenium.webdriver.common.by import By import time option = ChromeOptions() option.add_argument("--headless") with Chrome(options=option) as driver: # 打开有道翻译网站 driver.get("https://fanyi.youdao.com/") # 获取输入框 # 根据ID inputOriginal获取输入框 input_content = driver.find_element(By.ID, "inputOriginal") # 获取结果框 # 根据ID transTarget获取结果框 trans_content = driver.find_element(By.ID, 'transTarget') while True: # 输入翻译的内容 input_content.send_keys(input("请输入要翻译的内容")) # 延迟两秒获取翻译结果 time.sleep(2) print("翻译结果是:" + trans_content.text) # 清空输入框 input_content.clear()
标签:content,翻译,python,driver,爬取,输入框,input,ID From: https://www.cnblogs.com/xmgcool/p/16936938.html