'How to replace the data obtained by Selenium, in order to create patterns?
How can I replace the data received by selenium, and set defaults for them, example if the result is numbers from 1 to 7 display red in each of them.
from asyncio.windows_events import NULL
from ctypes.wintypes import PINT
from logging import root
import re
from tkinter import N
from hyperlink import URL
from selenium import webdriver
import selenium
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import time
url = "https://blaze.com/pt/games/double"
#absolute path
firefox_driver_path = "/Users/Antônio/Desktop/roletarobo/geckodriver.exe"
firefox_options = Options()
firefox_options.add_argument("--headless")
webdriver = webdriver.Firefox(
executable_path = firefox_driver_path,
options = firefox_options
)
with webdriver as driver:
# timeout
wait = WebDriverWait(driver, 20)
# retrieve data
driver.get(url)
#wait
wait.until(presence_of_element_located((By.CSS_SELECTOR, "div#roulette.page.complete")))
time.sleep(4)
results = driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")
for quote in results:
quoteArr = quote.text.split('\n')
print([my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:8])
data = [my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "div#roulette-recent div.entry")][:8]
Below are the results, and I want to replace them with 3 patterns, making conditions like if some number from 1-7 display red ex: 0 white 1-7 red 8-14 black
['8', '13', '10', '13', '', '13', '2', '1']
['black','black','black','black','white','black','red','red']
webdriver = webdriver.Firefox(
['8', '13', '10', '13', '', '13', '2', '1']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
