爬虫中的“句柄无效”错误和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  is not clickable at point (591,572) because another element  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)

你可能感兴趣的:(Python类,Python爬虫,selenium)