8

爬虫中的“句柄无效”错误和selenium.common.exceptions.ElementClickInterceptedExcept...

 3 years ago
source link: https://blog.csdn.net/lucky_chaichai/article/details/111994000
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

爬虫中的“句柄无效”错误和selenium.common.exceptions.ElementClickInterceptedException

1.使用selenium爬虫报错:OSError: [WinError 6] 句柄无效

原因:多次爬虫后没有成功关闭chromedriver.exe,导致后台含有多个chromedriver.exe 进程。
解决: 爬虫程序结束后使用driver.quit()

2.使用selenium爬虫时,find到的元素在click时报错:selenium.common.exceptions.ElementClickInterceptedException

具体错误信息:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <input class="el-radio__original" type="radio"> is not clickable at point (591,572) because another element <span class="el-radio__inner"> obscures it

错误解释:在爬虫过程中查找到的要点击的web element被其他元素覆盖(比如要选择的选项早前已经被选中)。
解决:
原始代码:

noodle= driver.find_elements_by_css_selector("input[value='面食']")
noodle.click()
noodle= driver.find_elements_by_css_selector("input[value='面食']")
driver.execute_script("arguments[0].click();", noodle)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK