0

when I go to this particular webpage you will see that there are a number of items that have particular price in Ethereum (ETH) attached to it: https://opensea.io/collection/beanzofficial?search[paymentAssets][0]=ETH&search[stringTraits][0][name]=Background&search[stringTraits][0][values][0]=Off%20White%20C&search[toggles][0]=BUY_NOW

For example, the first item in the picture below is "Bean #7474" and has a price of "1.37 ETH" enter image description here How can I get that price of 1.37 ETH by python? I tried to look at the "view-source:" of the page in Chrome, but the string 1.37 ETH does not show up. Also, I have used python to do:

req = Request(pageurl, headers={'User-Agent': 'User-Agent'})

html = urlopen(req).read()

but the html text of the page does not contain the '1.37 ETH' string. Is there any way I can get '1.37 ETH' using python by getting the html text of the page (ideally) or otherwise. Thank you

user3438258
  • 237
  • 1
  • 3
  • 9

1 Answers1

1

Check the below Python code: Updated code based on feedback received in the comments

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://opensea.io/collection/beanzofficial?search[paymentAssets][0]=ETH&search[stringTraits][0][name]=Background&search[stringTraits][0][values][0]=Off%20White%20C&search[toggles][0]=BUY_NOW")
wait = WebDriverWait(driver, 10)
product = wait.until(EC.visibility_of_element_located((By.XPATH, "(//span[@data-testid='ItemCardFooter-name'])[1]"))).text
amount = wait.until(EC.visibility_of_element_located((By.XPATH, "(//div[@data-testid='ItemCardPrice'])[1]//span//span[1]"))).text
print("Product name:" + product + "  " + "Amount:" + amount)

Imports:

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

Console output:

Product name:Bean #7474  Amount:1.37
Shawn
  • 4,064
  • 2
  • 11
  • 23
  • 1
    A couple feedback points... 1. you have declared two instances of `WebDriverWait(driver, 10)`. You can just declare one, stored it in a variable `wait`, and then reuse it when needed, e.g. `wait = WebDriverWait(driver, 10)` and then `wait.until(...)`. – JeffC Apr 14 '23 at 15:25
  • 1
    2. You are using `EC.presence_of_element_located()` here which is risky. Presence means the element is in the DOM but not necessarily visible or interactable. Instead use `EC.visibility_of_element_located()` since you want to grab the `.text`. If the site loads slowly, there's a decent chance you'll get an element not interactable exception using presence. – JeffC Apr 14 '23 at 15:25
  • @JeffC - Fair enough. Updated answer now. – Shawn Apr 14 '23 at 15:55