Здравствуйте, у меня есть простой сценарий python здесь:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
options.add_argument("window-size=1400,800")
driver = webdriver.Chrome(options=options)
driver.get('https://www.coteur.com/cotes-foot.php')
#Store url associated with the soccer games
url_links = []
for i in driver.find_elements_by_xpath('//a[contains(@href, "match/cotes-")]'):
url_links.append(i.get_attribute('href'))
print(len(url_links), '\n')
print(url_links, '\n')
Этот сценарий отлично работает на моем Ubuntu P C, но когда я пытаюсь запустить его с сервера ec2 ubuntu, этого не происходит работает.
Вот моя конфигурация EC2:
DNS publi c (IPv4): ec2-3-21-128-62.us-east-2.compute.amazon aws .com ID d'AMI: ubuntu / images / hvm-ssd / ubuntu-bioni c -18.04-amd64-server-20200611 (ami-0a63f96e85105c6d3)
Я указываю, что google chrome и chromedriver установлены на моем сервере EC2.
Когда я запускаю скрипт из EC2, у меня появляется следующее сообщение об ошибке:
Traceback (most recent call last):
File "./test.py", line 17, in <module>
url_links.append(i.get_attribute('href'))
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 141, in get_attribute
self, name)
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 636, in execute_script
'args': converted_args})['value']
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.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: headless chrome=83.0.4103.116)