我成功创建了一个从图表平台 tradingview 下载股票数据的 python 脚本。当我从本地机器启动它时,一切正常。
现在我想从 ubuntu ec2 机器和 crontab 启动脚本。几天前,我第一次尝试从 ec2 机器手动运行脚本。今天我想尝试设置 crontab。它没有用,所以我尝试再次手动启动 python 脚本。这次我得到这个错误。
File "automated_prediction_ec2.py", line 282, in <module>
signin.click()
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: headless chrome=86.0.4240.75)
首先我认为可能是因为 tradingview 改变了他们的 HTML,所以我尝试从我的本地机器上运行它。这和以前一样完美。
这些是我的 ChromeOptions。我已经尝试了几种组合来解决问题,但这些是上次有效的组合。
options = webdriver.ChromeOptions()
prefs = {'download.default_directory' : '/home/ubuntu/daily_stock_data'}
options.add_argument('--headless')
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_experimental_option('prefs', prefs)
那么可能是什么问题,有一天我的脚本在 ec2 机器上运行,然后突然我得到了这个错误?此外,该脚本正在下载 130 个 CSV。ec2 实例是否有下载限制之类的东西?
这是发生错误的代码。
driver.get("https://www.tradingview.com/")
driver.implicitly_wait(20)
signin = driver.find_element_by_class_name("tv-header__link.tv-header__link--signin.js-header__signin")
signin.click()
页面的 HTML 片段。
<span class="tv-header__dropdown-text">
<a class="tv-header__link tv-header__link--signin js-header__signin" href="#signin">Sign in</a>
</span>