You don't have to create a for loop for the empty list... try using this code:
results=driver.find_elements_by_xpath("//div[@id='links']/div/div/div[2]")
description=[]
for result in results:
description.append(result.text)
Example:
To test this I simply typed 'hmm' in DuckDuckGo so the URL is https://duckduckgo.com/?q=hmm&t=h_&ia=web
from selenium import webdriver
driver=webdriver.Chrome()
driver.get('https://duckduckgo.com/?q=hmm&t=h_&ia=web')
results=driver.find_elements_by_xpath("//div[@id='links']/div/div/div[2]")
description=[]
for result in results:
description.append(result.text)
print(description[0])
print(' ')
print(description[1])
print(' ')
print(description[2])
Output:
HMM to Develop "New-GAUS 2020"... HMM Holds 'PSA-Hyundai Pusan N... HMM Names New VLCC, 'Universal... 2019 New Year's Message; The HMM's Future Plan; HMM Blueprint for the Year 202... HMM signed the formal contract...
Hmm definition, (used typically to express thoughtful absorption, hesitation, doubt, or perplexity.) See more.
2 � used to emphasize that one has asked a question and is awaiting an answer But tell Santa the truth now, what's the most important part to a little boy or girl? The box
The search results:
