Selenium:访问CAISO网站时“元素不可操作错误”,但只有downloadNetDemandCSV,downloadDemandCSV没有问题

0 投票
0 回答
49 浏览
提问于 2025-04-12 08:35
browser.find_element_by_id('downloadDemandCSV').click() #download CSV file

我正在尝试修复这段代码,以便从中提取数据。这个代码可以在这里公开获取:https://github.com/grgmiller/CAISO_operations/blob/master/CAISO_operations.py

这段代码在2020年时是可以正常工作的,但现在由于网站的细微变化以及使用了一些不再支持的方法,导致它无法正常运行。

我做的第一件事是把selenium降级到4.0.0版本,以排除那些因为不再支持的方法而产生的错误。接下来,我在downloadCurtialment函数中添加了一行代码,位置在

curtail_read = pd.read_csv(curtailments / 'curtailment_data.csv', dtype=ct_dtypes) #load the csv into a dataframe

之后:

curtail_read = curtail_read.drop(columns=['Reason']) # Reason is not needed

在代码中使用的数据集中原本没有“Reason”这一列,所以我把它从数据框中删除了。

我现在遇到的问题是downloadDemand函数中的倒数第二行代码:

browser.find_element_by_id('downloadNetDemandCSV').click() #download CSV file

我得到了这个错误信息:

  File "/home/luis/Research/CAISO_operations/CAISO_operations.py", line 101, in main
    downloadDemand(browser, dataDate)
  File "/home/luis/Research/CAISO_operations/CAISO_operations.py", line 253, in downloadDemand
    browser.find_element_by_id('downloadNetDemandCSV').click() #download CSV file
  File "/home/luis/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/home/luis/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 693, in _execute
    return self._parent.execute(command, params)
  File "/home/luis/.local/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "/home/luis/.local/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=123.0.6312.58)

我对这个错误有点迷茫,因为它在处理downloadDemand.csv时可以正常工作。我检查了浏览器控制台,发现“downloadDemandCSV”和“downloadNetDemandCSV”都在下拉菜单中。我无法弄清楚到底是什么地方出错了。这里是代码所引用的网站:http://www.caiso.com/TodaysOutlook/Pages/default.aspx#section-net-demand-trend

我使用的是Linux Mint 21.2和Chromium 123.0.6312.58

谢谢大家的帮助,如果这有什么简单的错误,我很抱歉,我对selenium和网络爬虫还很陌生。

0 个回答

暂无回答

撰写回答