代码改了一下:from selenium import webdriver
import time
content = input('请输入你需要翻译的内容:')
options = webdriver.IeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
browser = webdriver.Ie(options = options)
browser.get('https://fanyi.baidu.com')
input_area = browser.find_element_by_css_selector('#baidu_translate_input')
input_area.send_keys(content)
time.sleep(2)
output_area = browser.find_element_by_css_selector('#main-outer > div > div > \
div.translate-wrap > div.translateio > div.translate-main.clearfix > \
div.trans-right > div > div > div.output-bd > \
p.ordinary-output.target-output.clearfix > span')
print('翻译结果:',output_area.text)
browser.close()
结果:请输入你需要翻译的内容:hello
Traceback (most recent call last):
File "C:\Users\admin\Desktop\hello.py", line 10, in <module>
input_area = browser.find_element_by_css_selector('#baidu_translate_input')
File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 598, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "D:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with css selector == #baidu_translate_input
IE能正常启动,这是什么情况 |