0
#iFrame
driver.switch_to.frame(driver.find_element_by_css_selector("#iFrameResizer0"))

#Findings elements
time.sleep(2) #Sleep to avoid 'laiks' error?
laiks = driver.find_elements_by_class_name("event-date-time__time")
time.sleep(3)
speles = driver.find_elements_by_class_name("event-block-row__name")
time.sleep(4)
odds = driver.find_elements_by_class_name("odd__value")

if laiks and speles and odds is not None:
    print("Plkst., Spēlētāji, Koeficients:")
#Create datas.txt, write into it
with open("datas.txt", "w") as output:
    for viss in laiks + speles + odds:
        #Print in console the above
        print(viss.text);
        #Write in output file
        output.write(viss.text + " | ")

This produces the following in the data.txt file:

23:30 | 23:30 | 22:00 | 22:30 | 23:30 | 08:00 | 11:00 | 14:00 | 16:00 | 15:00 | 18:30 | 22:00 | 15:00 | 20:00 | Havan Liberty - Isurus Gaming | Boom.id - Sharks Esports | Sector One - 4Elements Esports | Sprout - Divizon | Gamefist - Jointheforce | Touch The Crown - Unicorns of Love | Unicorns of Love - Touch The Crown | Huat Zai - After Gaming | Beyond Esports - Zigma | Tiger - Invictus Gaming | C0ntact Gaming - Mousesports | North - Sprout | Natus Vincere - Mousesports | Complexity Gaming - ENCE | BIG - Team Spirit | Astralis - Heroic | Evil Geniuses - Furia Esports | Liquid - 100 Thieves | 2.08 | 1.67 | 1.48 | 2.42 | 3.70 | 1.25 | 

However, this is not the desired result and is hard to understand. First value of "laiks" represents first value of "speles" and first two "odds" values.

23:30 | Havan Liberty - Isurus Gaming | 2.08 | 1.67 |
23:30 | Boom.id - Sharks Esports | 1.48 | 2.42 |

How would I do this?

  • You seem to be looking for [`zip`](https://docs.python.org/3/library/functions.html#zip) but there is a lot of irrelevant code here. Please [edit] to reduce your problem to a [mre] which doesn't require us to install Chrome drivers etc to solve a simple Python problem. – tripleee Sep 24 '20 at 18:51
  • 1
    Something like this? https://ideone.com/QOE9Tl – tripleee Sep 24 '20 at 19:13
  • @tripleee This is the result I am looking for. As I understand the zip() function pairs first 'laiks' with first 'speles' and first 'odds'. Then the second 'laiks' with second 'speles' and second 'odds' so on and so forth, right? The problem is that when I place the zip function in my .py file it gives me a long ' – notsoexperienced Sep 25 '20 at 14:24
  • Without seeing the code and the actual error message, not much I can say. Probably post a new question with your current attempt. – tripleee Sep 26 '20 at 09:35

1 Answers1

1

Your arrays seem to be not of equal size, so you will have to handle that first and then use for loop to piece them together with the separator you need and write it to the file inside the context.

laiks = ['23:30 ',
         ' 23:30 ',
         ' 22:00 ',
         ' 22:30 ',
         ' 23:30 ',
         ' 08:00 ',
         ' 11:00 ',
         ' 14:00 ',
         ' 16:00 ',
         ' 15:00 ',
         ' 18:30 ',
         ' 22:00 ',
         ' 15:00 ',
         ' 20:00']
speles = ['Havan Liberty - Isurus Gaming ',
          ' Boom.id - Sharks Esports ',
          ' Sector One - 4Elements Esports ',
          ' Sprout - Divizon ',
          ' Gamefist - Jointheforce ',
          ' Touch The Crown - Unicorns of Love ',
          ' Unicorns of Love - Touch The Crown ',
          ' Huat Zai - After Gaming ',
          ' Beyond Esports - Zigma ',
          ' Tiger - Invictus Gaming ',
          ' C0ntact Gaming - Mousesports ',
          ' North - Sprout ',
          ' Natus Vincere - Mousesports ',
          ' Complexity Gaming - ENCE ',
          ' BIG - Team Spirit ',
          ' Astralis - Heroic ',
          ' Evil Geniuses - Furia Esports ',
          ' Liquid - 100 Thieves ']
odds = ['2.08',
        '1.67',
        '1.48',
        '2.42',
        '3.70',
        '1.25']

# handle unequal size array
max_samples = max(len(laiks), len(speles), len(odds))
# equalize the arrays
for array in [speles, laiks, odds]:
    if len(array) < max_samples:
        array = array.extend([' '] * (max_samples - len(array)))
# piece them together
for i in range(max_samples):
    print laiks[i] + '|' + speles[i] + '|' + odds[i]
    # output.write(laiks[i] + '|' + speles[i] + '|' + odds[i])

output

23:30 |Havan Liberty - Isurus Gaming |2.08
 23:30 | Boom.id - Sharks Esports |1.67
 22:00 | Sector One - 4Elements Esports |1.48
 22:30 | Sprout - Divizon |2.42
 23:30 | Gamefist - Jointheforce |3.70
 08:00 | Touch The Crown - Unicorns of Love |1.25
 11:00 | Unicorns of Love - Touch The Crown | 
 14:00 | Huat Zai - After Gaming | 
 16:00 | Beyond Esports - Zigma | 
 15:00 | Tiger - Invictus Gaming | 
 18:30 | C0ntact Gaming - Mousesports | 
 22:00 | North - Sprout | 
 15:00 | Natus Vincere - Mousesports | 
 20:00| Complexity Gaming - ENCE | 
 | BIG - Team Spirit | 
 | Astralis - Heroic | 
 | Evil Geniuses - Furia Esports | 
 | Liquid - 100 Thieves | 
sai
  • 1,734
  • 1
  • 7
  • 13