Problem collecting links from a site

0

Expensive, good morning! I'm writing a program in Python to collect links from a website. The part of the code that collects the links is:

links = driver.find_elements_by_xpath('//*[@href]')
for link in links:
    print(link.get_attribute('href'))
time.sleep(1)

I tested it on some websites and ran good. The problem is when I use in Ifood. It collects some links and then returns several errors. I'm pretty new to programming so I do not know what those mistakes mean and how I can get around it. If anyone could help me, I would be very grateful! Thanks =)

What the code returns:

https://d1jgln4w9al398.cloudfront.net/imagens/ce/wl/www.ifood.com.br/favicon.ico
https://d1jgln4w9al398.cloudfront.net/site/2.1.238-20181023.22/css/main.css
https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800
https://www.ifood.com.br/

Traceback (most recent call last):
  File "C:\Users\jorda\Desktop\Python - Projetos\digitar ifood.py", line 32, in <module>
    print(link.get_attribute('href'))
  File "C:\Users\jorda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 143, in get_attribute
    resp = self._execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name})
  File "C:\Users\jorda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\jorda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\jorda\AppData\Local\Programs\Python\Python37-32\lib\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: chrome=70.0.3538.77)
  (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.17134 x86_64)
    
asked by anonymous 31.10.2018 / 13:48

0 answers