为什么运行selenium时会出现错误

2024-09-28 20:17:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我的错误:

C:\Users\Owner\OneDrive\Desktop\code\webscraping>
[19332:5236:0814/205141.538:ERROR:device_event_log_impl.cc(214)] [20:51:41.538] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[19332:5236:0814/205141.538:ERROR:device_event_log_impl.cc(214)] [20:51:41.538] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

我的代码:

1 from selenium import webdriver                                                                                                                                                                                                               
2 from selenium.webdriver.common.keys import Keys                                                                                                                                                                                              
3 from selenium.webdriver.common.by import By                                                                                                                                                                                                  
4 from selenium.webdriver.support.ui import WebDriverWait                                                                                                                                                                                      
5 from selenium.webdriver.support import expected_conditions as EC                                                                                                                                                                             
6 import time                                                                                                                                                                                                                                  
7                                                                                                                                                                                                                                              
8 PATH = "C:\Program Files (x86)\chromedriver.exe"                                                                                                                                                                                             
9                                                                                                                                                                                                                                             
10 driver = webdriver.Chrome(PATH)                                                                                                                                                                                                             
11 driver.get('https://techwithtim.net/')                                                                                                                                                                                                      
12                                                                                                                                                                                                                                             
13 #link = driver.find_element_by_id('menu-item-402')                                                                                                                                                                                          
14 #link.click()                                                                                                                                                                                                                               
15                                                                                                                                                                                                                                             
16 try:                                                                                                                                                                                                                                        
17     element = WebDriverWait(driver, 10).until(                                                                                                                                                                                              
18         EC.presence_of_element_located((By.LINK_TEXT, "Beginner Python Tutorials"))                                                                                                                                                         
19     )                                                                                                                                                                                                                                       
20     element.click()                                                                                                                                                                                                                         
21 except:                                                                                                                                                                                                                                     
22     driver.quit()

代码的教程在这里(不是我的代码) the tutorial


Tags: theto代码fromimporteventlogdevice