Witam, napisałem mały skrypt, który wyciąga ze strony AWS ceny Reserved Instances i zwraca na ekran nazwę instancji oraz jej cenę (koniecznie Convertible 3-year term). Niby wszystko działa, ale bardzo wolno, zapewne też przez to, że lista allElements zawiera 1925 elementów, a później iteruje po wszystkich jej elementach. Chciałbym pofiltrować te dane tak jak w kodzie, ale czy jest opcja zrobienia tego szybciej jakoś "in place" i nie ładować wszystkiego do tej listy allElements, a później jeszce iterować po niej element po elemencie z ifem? Dzięki z góry za pomoc!
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
import time
caps = DesiredCapabilities().FIREFOX
#caps["pageLoadStrategy"] = "normal" # complete
#caps["pageLoadStrategy"] = "eager" # interactive
caps["pageLoadStrategy"] = "none"
browser = webdriver.Firefox(desired_capabilities=caps)
browser.get('https://aws.amazon.com/ec2/pricing/reserved-instances/pricing/')
delay=3
time.sleep(10)
#browser.find_element_by_link_text('Windows').click()
try:
myElem = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.CLASS_NAME, 'aws-plc-content')))
print ("Page is ready!")
except TimeoutException:
print ("Loading took too much time!")
time.sleep(2)
allElements=browser.find_elements_by_class_name("aws-pricing-table-wrapper")
for el in allElements:
lista=el.text.split("\n")
indeks=lista.index("CONVERTIBLE 3-YEAR TERM")
prices=lista[indeks+2]
if lista[0].startswith('c5'):
print(lista[0])
print(prices.split()[4])