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('http://w=w=w.a@i#e$s.c&n/') # 要把特殊字符去掉
# 获取文本输入框
# 通过标签的ID "txt"获取标签
input_content = driver.find_element(By.ID, 'txt')
# 获取简体转繁体按钮
# 通过标签的属性value值为"简体转繁体"获取标签
button_content = driver.find_element(By.XPATH, '//input[@value="简体转繁体"]')
while True:
# 输入转换内容
input_content.send_keys(input("请输入要转换的内容"))
# 点击简体转繁体按钮
button_content.click()
# 延迟1秒后,获取转换结果
time.sleep(1)
# get_attribute()获取对应属性的值
print(input_content.get_attribute('value'))
# 清空文本框
input_content.clear()