So I’m trying to create a bot that identifies nft loan listings on blur that meet certain criteria such as the loans total value being 80% or less than its floor price or APY being greater than 100%. I’ve figured out the basics of loading up chrome using selenium and navigating to the correct section of the website to view a collections loans. But I’m struggling to actually extract the data from the table of loans. What id like to be able to do is extract the table of loan listings into an array of arrays or array of dictionaries, with each array/dictionary containing data representing each name, status, borrow amount, LTV, and APY.
What I have working thus far:
import selenium
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
path = "/Users/#########/Desktop/chromedriver-mac-arm64/chromedriver"
# Create an instance of ChromeOptions
options = Options()
options.add_experimental_option("detach", True)
options.add_argument("disable-infobars");
# Specify the path to the ChromeDriver
service = Service(path)
# Initialize the WebDriver with the service and options
driver = webdriver.Chrome(service=service, options=options)
# Open Blur beanz collection and navigating to active loans page
driver.maximize_window
driver.get("https://blur.io/eth/collection/beanzofficial/loans")
time.sleep(3)
loan_button = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div[3]/div/div[2]/div[1]/div[1]/nav/button[2]")
loan_button.click()
I’m honestly new to selenium, so I’ve just been toying around with my intuition and chatgpt trying to solve this. The best guess I’ve had so far was the following bit of code that tried to extract the APY of all the loans. This did not work, as im sure there was some faulty intuition.
elements = driver.find_elements(By.CSS_SELECTOR, 'Text-sc-m23s7f-0 hAGCAO')
# Initialize an empty list to store the percentage values
percentages = []
# Iterate through each element and extract its text (which contains the percentage)
for element in elements:
percentage = element.text
percentages.append(percentage)
# Print the extracted percentage values
print(percentages)
time.sleep(10)
# Close the WebDriver
driver.quit()
I also feel like this is a bit complex, having to extract each column in the table rather than each row at a time. Not sure if there is a simpler way to do this, if there was that would be great. If not ok too!