H
H
haniaman2020-09-11 13:32:55
Python
haniaman, 2020-09-11 13:32:55

Why is incorrect data displayed when parsing?

I am writing a parser for a site, the data that should be parsed is updated all the time, and I ran into such a problem that it displays incorrect data, namely: https://imgur.com/a/iOQ5lNl - should display (from bottom to top), but displays https ://imgur.com/a/6y0KvIv . The color is determined by the class of the child element. And the output of new games by the hash of the game. I made it to display the 3rd game.

from selenium import webdriver
import time
import csv

driver = webdriver.Chrome()

driver.get("https://rublix.best/")

time.sleep(45)
wheel = driver.find_element_by_xpath("/html/body/div[1]/div[1]/nav/ul[1]/li[2]/a").click()
hash_game = 0
a = 1

'''  Выводит каждую третью игру то есть 0 - грин, 1- ред, 2- грей.
 Выведет грей, на следующей игре ред и тг  '''

while True:
    last_game = driver.find_element_by_xpath('//*[@id="doubleGame"]/div[1]/div[3]/div/div[3]/div').get_attribute('class')
    color = 0

    named_tuple = time.localtime() # получить struct_time.
    time_string = time.strftime("Время: %H:%M:%S", named_tuple)

    h = driver.find_element_by_xpath('//*[@id="doubleGame"]/div[1]/div[3]/div/div[3]/div/div/span[1]/p') # путь до хеша последней игры
    if hash_game != h:
        hash_game = h
        if last_game == 'lggr':
            color = 'GREEN'
        elif last_game == 'lgg':
            color = 'GREY'
        elif last_game == 'lgb':
            color = 'BLUE'
        elif last_game == 'lgr':
            color = 'RED'

        t = [str(a), 'game', '{}'.format(color), '{}'.format(time_string)]
        print(t)
        a += 1

        myFile = open('doubleGame.csv', 'a', newline='')
        with myFile:
            writer = csv.writer(myFile, delimiter=';') # Записывает в myFile с разделителем ';' для перехода в след. ячейку.
            writer.writerows([t]) # Записывает список списка переменной t, иначе через каждый символ будет запятая.
        time.sleep(3)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question