这是在调用selenium过程中出现的错误提示,经过调试发现是在查询driverChrome过程无法找到文件所致:后来在系统文件中加入了driverChrome.exe所在路径,还是不行,后来我看了网上说把这个文件的地址放到driver=driver.Chrome("driverChrome路径"),就可以正常调用chrome文件了。
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\Python\test\p.py", line 9, in
driver=webdriver.Chrome()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
#pip install selenium
from selenium import webdriver
import time
-----------------------------------------------------------------------------
patha=r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'
print(patha)
driver=webdriver.Chrome(patha)
#可以使用r()函数进行原字符串转义
-----------------------------------------------------------------------------
#driver=webdriver.Chrome("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe")
driver=webdriver.Chrome()
driver.maximize_window()
time.sleep(5)
#发送请求
driver.get('https://www.baidu.com/')
driver.find_element_by_id("kw").send_keys("python")
driver.find_element_by_id("su").click()
driver.find_element_by_xpath('//*[@id="su"]')
地址:https://www.cnblogs.com/testway/p/8079237.html