I am trying to scrape a website and I am using following code:
import selenium
titles=[]
driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
for i in range(len(links)):
driver.get(links[i])
time.sleep(0.5)
data = driver.find_elements_by_xpath('.//a[@class = "question-hyperlink"]')
titles.append(data[0].text)
I am running this code on google colab. The problem I am getting is that data doesn't store any value after loop iterates for some values. If I restart the kernel and rerun code then code works fine for the earlier iteration and the same issue occurs at another iteration. I am confused about why is it happening. I tried so many things but nothing work. Also, the size of links is large so is there any way to speed up things?
Edit: Added link to full code: https://colab.research.google.com/drive/1SYIA_SUPYzlR-K9ph4grNem-LbL61uB7?usp=sharing