I'm creating a script that scraps currency names and prices. whenever I run my script it works perfectly fine but the problem is it does not print in order format like if the bitcoin price is $65,056.71
it will write another coin price in bitcoin line.
In this way, it writes random values to each line
Here is my code:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="chromedriver.exe")
driver.get("https://coinmarketcap.com/")
driver.implicitly_wait(10)
coins = set()
coin_names = driver.find_elements_by_class_name('iworPT')
print(coin_names)
for names in coin_names:
coins.add(names.text)
for coins_val in coins:
print(coins_val)
# coins price
coinsprice = []
get_coin_price = driver.find_elements_by_class_name('cLgOOr')
for price in get_coin_price:
coinsprice.append(price.text)
for price_val in coinsprice:
print(price_val)
with open('coins.txt', 'w') as f:
for coins_name, prices in zip(coins,coinsprice):
f.write(coins_name + ": " + prices + "\n")
driver.close()
Thanks in advance.