Reputation: 115
I am learning how to use Selenium with Python and have been toying around with a few different things. I keep having an issue where I cannot locate any classes. I am able to locate and print data by xpath, but I cannot locate the classes.
The goal of this script is to gather a number from the table on the website and the current time, then append the items to a CSV file.
Site: https://bitinfocharts.com/top-100-richest-dogecoin-addresses.html
Any advice or guidance would be greatly appreciated as I am new to python. Thank you.
Code:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
import time
import pandas as pd
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import csv
from datetime import datetime
from selenium.webdriver.common.by import By
#Open ChromeDriver
PATH = ('/Users/brandon/Desktop/chromedriver')
driver = webdriver.Chrome(PATH)
driver.get("https://bitinfocharts.com/top-100-richest-dogecoin-addresses.html")
driver.implicitly_wait(10)
driver.maximize_window()
#Creates the Time
now = datetime.now()
current_time = now.strftime("%m/%d/%Y, %H:%M:%S")
#####
#Identify the section of page
page = driver.find_element(By.CLASS_NAME,'table table-condensed bb')
time.sleep(3)
#Gather the data
for page in pages():
num_of_wallets = page.find_element(By.XPATH,
"//html/body/div[5]/table[1]/tbody/tr[10]/td[2]").text
table_dict = {"Time":current_time,
"Wallets":num_of_wallets}
file = open('dogedata.csv', 'a')
try:
file.write(f'{current_time},{num_of_wallets}')
finally:
file.close()
Upvotes: 1
Views: 111
Reputation: 33353
table table-condensed bb
actually contains 3 class names.
So the best way to locate element based on multiple class names is to use css selector or xpath like:
page = driver.find_element(By.CSS_SELECTOR,'.table.table-condensed.bb')
or
page = driver.find_element(By.XPATH,"//*[@class='table table-condensed bb']")
Upvotes: 2