You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行Python的fuf.py脚本时出现弃用警告及属性错误求助

解决Selenium运行Instagram脚本时的错误问题

你遇到的错误包含三个部分,以下是针对性的解决方法:

1. 处理executable_path废弃警告

Selenium 4.x版本已移除executable_path参数,需改用Service对象初始化ChromeDriver:

修改代码中初始化浏览器的部分:

# 先导入Service类
from selenium.webdriver.chrome.service import Service

# 替换原初始化代码
service = Service(ChromeDriverManager().install())
browser = webdriver.Chrome(service=service, options=options)

2. 屏蔽USB设备读取错误(非致命,可选处理)

这类错误是ChromeDriver与Windows USB设备的兼容性问题,不影响脚本执行,可通过添加Chrome选项关闭日志输出:

options.add_experimental_option('excludeSwitches', ['enable-logging'])

3. 修复AttributeError致命错误

Selenium 4.x已删除find_element_by_css_selector等旧版元素定位方法,统一使用find_element()配合By类:

修改元素定位的代码:

# 先导入By类
from selenium.webdriver.common.by import By

# 替换原定位代码
username_input = browser.find_element(By.CSS_SELECTOR, "input[name='username']")

其他类似find_element_by_id、find_element_by_xpath的方法,都需要对应替换为By.ID、By.XPATH等参数。

执行以上修改后,脚本即可正常运行。

内容的提问来源于stack exchange,提问作者Suram Pathiraja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 21:35:24