解决爬虫错误:AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_id‘

1. 问题:

        在学习爬虫中的selenium部分时,出现AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'问题。

2.原因:

        由于版本迭代,新版的selenium已经不再使用find_element_by_id方法。

3. 解决办法:

        将button = browser.find_element_by_id('su')修改为如下语句,

button = browser.find_element(By.ID,'su')

        再在其代码页的最前端添加下列代码,

from selenium.webdriver.common.by import By

物联沃分享整理
物联沃-IOTWORD物联网 » 解决爬虫错误:AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_id‘

发表评论