'Stuck with scraping data

Firts I want to say thanks to all who have asked questions here and ofc to those who have answered. I have learned a lot from questions and answers, from 0 to how scrape websites and I am STILL LEARNING. I have successfully and without a problem scraped websites where I need to get data from specific element and so on. But now I am facing different problem here. I have cracked my head over a week and cant find a solution how I can add variable for each element so it writes correctly csv file. Hope it doesnt sound mambo-jambo what I am talking here :)

So here is my full code until problems

#import modules
import selenium.webdriver as webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep 
import csv

#get driver and open website
browser = webdriver.Chrome(executable_path=r'C:\Users\loom\Desktop\chromedriver_win32\chromedriver.exe')
browser.get('https://www.flashscore.com/football/netherlands/eredivisie-2012-2013/results/')
sleep(1)

#click cookie button OK
browser.find_element_by_xpath('.//*[@id="onetrust-accept-btn-handler"]').click()
sleep(1)

#load more matches
pages_remaining = True

while pages_remaining:
    try:
        browser.find_element_by_xpath('.//a[@class="event__more event__more--static"]').click()
        sleep(3)
    except:
        browser.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
        break

results = ui.WebDriverWait(browser, 15).until(lambda browser: browser.find_elements_by_xpath(".//*[starts-with(@id,'g_1_')]"))

# Save the window opener (current window, do not mistaken with tab... not the same)
main_window = browser.current_window_handle
sleep(2)

#create csv file
file = open('AAsoccer.csv', 'w', newline='')
writer = csv.writer(file,delimiter=';')
writer.writerow(['1goal','1goalt','2goal','2goalt','3goal','3goalt','4goal','4goalt','5goal','5goalt','6goal','6goalt'])

#open sample game
for link in results[14:15]:
    link.click()
    browser.switch_to.window(browser.window_handles[-1])

#find incidents,time,scores
incidents = browser.find_elements_by_xpath('.//div[@class="smv__incident"]')
time = browser.find_elements_by_xpath('.//div[@class="smv__incident"]//div[@class="smv__timeBox"]')
goals = browser.find_elements_by_xpath('.//div[@class="smv__incidentIcon"]//div')
len(goals)

The next code blocks is where the problems start

#show goals
for goal in goals:
    print(goal.text)
1 - 0
2 - 0
2 - 1
3 - 1
3 - 2
4 - 2

and

#show time
for ti in time:
    print(ti.text)
19'
24'
33'
43'
55'
56'
60'
63'
65'
67'
73'
83'
84'
85'
86'
89'

The problem is I cant figure out how to combine or add variable to SCORE and TIME and write it to csv. Example how the csv file should look like:

1goal 1goalt 2goal 2goalt 3goal 3goalt 4goal 4goalt
1-0 19' 2-0 55' 2-1 65' 3-1 67' 85'

here is direct link to match https://www.flashscore.com/match/WpvSuTXn/#/match-summary/match-summary

edit so if I change code like that,it prints TIME AND SCORE combined. But the score remains the first element

for goal in goals:
    time = browser.find_element_by_xpath('.//div[@class="smv__timeBox"]/following::div/div')
    print(goal.text+time.text)
19'1 - 0
24'1 - 0
33'1 - 0
43'1 - 0
55'1 - 0
56'1 - 0
60'1 - 0
63'1 - 0
65'1 - 0
67'1 - 0
73'1 - 0
83'1 - 0
84'1 - 0
85'1 - 0
86'1 - 0
89'1 - 0

or trying to get specific result, it returns 1-0 again. But the correct score is 2-0

for goal in goals[4:5]:
    time = browser.find_element_by_xpath('.//div[@class="smv__timeBox"]/following::div/div')
    print(goal.text+time.text)
55'1 - 0


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source