0
点赞
收藏
分享

微信扫一扫

selenium爬虫find_element_by_*已被废弃使用find_element来代替

软件共享软件 2022-01-31 阅读 100

原先的写法

el = web.find_element_by_xpath('//*[@id="changeCityBox"]/p[1]/a')
web.find_element_by_xpath('//*[@id="search_input"]').send_keys('python',Keys.ENTER)
li_list = web.find_elements_by_xpath('//*[@id="jobList"]/div[1]/div')

出现一下警告:

现在的写法:

el = web.find_element(By.XPATH,'//*[@id="changeCityBox"]/p[1]/a')
web.find_element(By.XPATH,'//*[@id="search_input"]').send_keys('python',Keys.ENTER)
li_list = web.find_elements(By.XPATH,'//*[@id="jobList"]/div[1]/div')
By需要提前导入:
from selenium.webdriver.common.by import By

亲测有效,无警告。

举报

相关推荐

0 条评论