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

Python Selenium爬取Investing.com时Firefox驱动点击隐藏下拉项后闪退的解决求助

Python Selenium爬取Investing.com时Firefox驱动点击隐藏下拉项后闪退的解决求助

各位技术大佬们好!我最近在用Python Selenium爬取Investing.com土耳其区的股票页面,碰到了一个棘手的问题:当我点击隐藏下拉菜单里的"BİST Ulusal Tüm"选项时,Firefox驱动直接闪退关闭了,根本没法继续后续的爬取操作。

这个下拉菜单本身是隐藏状态的,我原本想着用显式等待来确保元素可点击后再操作,但试了好几次都没解决闪退的问题。下面是我目前的代码,麻烦大家帮我看看哪里出问题了,或者有没有什么更合适的处理方式?

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver

driver = webdriver.Firefox()
url = "https://tr.investing.com/equities/turkey"
driver.get(url)

driver.implicitly_wait(5)

WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="index-select"]'))).click()
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="index-select"]/div[2]/div/div/div[6]'))).click()

我试过调整显式等待的时长,也把隐式等待和显式等待结合起来用,但还是没解决闪退的问题。有没有大佬知道针对这种隐藏下拉菜单,有没有什么特殊的点击方式或者需要额外处理的地方?

备注:内容来源于stack exchange,提问作者Gokita

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.21 12:44:38