find_element_by_id()方法的使用上。这个方法已经被弃用,建议使用find_element()方法替代。

python 复制代码
from selenium import webdriver
path = 'chromedriver.exe'
browser = webdriver.Chrome(path)
url = 'https://www.baidu.com'
browser.get(url)
button = browser.find_element_by_id('su')
print(button)

修改后代码

python 复制代码
from selenium import webdriver
path = 'chromedriver.exe'
browser = webdriver.Chrome(path)
url = 'https://www.baidu.com'
browser.get(url)
# 使用 find_element() 方法替代 find_element_by_id()
button = browser.find_element('id', 'su')
print(button)

报错原因:webdriver.Chrome()的参数路径错误。

修改后的代码:

python 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

path = 'chromedriver.exe'
service = Service(executable_path=path)
browser = webdriver.Chrome(service=service)

url = 'https://www.baidu.com'

browser.get(url)

# 使用 find_element() 方法替代 find_element_by_id()
button = browser.find_element('id', 'su')
print(button)

但是,虽然出现报错信息,但是有运行结果,可以修改代码,也可以不修改!!!

相关推荐
郝学胜-神的一滴1 天前
深入浅出网络协议:从OSI七层到TCP/IP五层模型全解析
开发语言·网络·c++·网络协议·tcp/ip·程序人生
深蓝海拓1 天前
PyQt5/PySide6的moveToThread:移动到线程
笔记·python·qt·学习·pyqt
qq_406176141 天前
吃透JS异步编程:从回调地狱到Promise/Async-Await全解析
服务器·开发语言·前端·javascript·php
幻云20101 天前
Python深度学习:筑基与实践
前端·javascript·vue.js·人工智能·python
被星1砸昏头1 天前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
@大迁世界1 天前
停止使用 innerHTML:3 种安全渲染 HTML 的替代方案
开发语言·前端·javascript·安全·html
avi91111 天前
简单的Gradio实现一个统计界面+日志输出
python·aigc·gradio
52Hz1181 天前
力扣240.搜索二维矩阵II、160.相交链表、206.反转链表
python·算法·leetcode
jun_bai1 天前
conda环境配置nnU-Net生物医学图像分割肺动脉静脉血管
开发语言·python
子非鱼9211 天前
Vue框架快速上手
前端·javascript·vue.js