I am trying to build a webscraper with python / selenium that scrapes data from multiple websites and stores the data in an Excel sheet.
The sites I want to scrape are the following:
https://www.ngm.se/marknaden/vardepapper?symbol=ETH%20ZERO%20SEK
https://www.ngm.se/marknaden/vardepapper?symbol=BTC%20ZERO%20SEK
https://www.ngm.se/marknaden/vardepapper?symbol=VALOUR%20CARDANO%20SEK
https://www.ngm.se/marknaden/vardepapper?symbol=VALOUR%20POLKADOT%20SEK
https://www.ngm.se/marknaden/vardepapper?symbol=VALOUR%20SOLANA%20SEK
https://www.ngm.se/marknaden/vardepapper?symbol=VALOUR%20UNISWAP%20SEK
From all sites I want to scrape the "Omsättning", "Volym" and "VWAP" values and store them in an excel sheet.
This is what I got so far:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import ElementNotVisibleException
url = ["https://www.ngm.se/marknaden/vardepapper?symbol=ETH%20ZERO%20SEK"]
driver = webdriver.Chrome()
driver.get('https://www.ngm.se/marknaden/vardepapper?symbol=ETH%20ZERO%20SEK')
iframe = driver.find_element(By.XPATH, '//iframe').get_attribute("src")
driver.get(iframe)
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//div[@id="detailviewDiv"]//thead[.//span[contains(text(),"Volym")]]/following-sibling::tbody')))
volym = element.text.split('\n')[-3]
vwap = element.text.split('\n')[-2]
Omsaettning = element.text.split('\n')[-4]
print(volym, vwap, Omsaettning)
With that I am able to print the values from the ETH ZERO SEK website, however how can I simultaneously also scrape the data from the other wesbites and then store it into an excel? Also is possible to program it so that selenium does not need to open the browser to save on computer ressources?
Thanks a lot for any help in advance!