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)

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

相关推荐
clz131452112 小时前
设备反欺诈的四大支柱:从设备指纹到关联图谱
开发语言·php
xn713312 小时前
实测 Codex CLI 0.154.0:response.failed 为什么会被 idle timeout waiting for SSE 覆盖
python·openai
李高钢12 小时前
Python Flask 框架入门:从零搭建你的第一个 Web 应用
前端·python·flask
码农学院12 小时前
外贸独立站GEO实战:用 Python 自动生成多语言 llms.txt 和 Schema 站点地图
人工智能·python·chatgpt·geo·geo优化·ai优化aio
mONESY12 小时前
LangChain 结构化输出三兄弟:ToolCall、OutputParser、withStructuredOutput 彻底讲透
javascript
jsjzsl212 小时前
独立自由度框架下核聚变的本体论本质与商业化技术新路径
人工智能·python·算法
Thomas.Sir12 小时前
第45课:TensorFlow|异常检测实战【工业设备数据故障识别模型搭建】
人工智能·python·tensorflow
知兀12 小时前
【前端】受控和非受控组件
前端·javascript·react
数商云企12 小时前
2026年西安电商智能客服开发选数商云企,技术稳交付快
大数据·python
无忧.芙桃12 小时前
C++内存管理
c语言·开发语言·c++·青少年编程