0

I am trying to get some data from a website called : https://dexscreener.com/ethereum/0x1a89ae3ba4f9a97b10bac6a77061f00bb956858b and i'm trying to get the element : /html/body/div[1]/div/main/div/div[2]/div/div[2]/div/div/div[1]/div[4]/div[2]/div[1]/div[1]/div[2]/span[2] which is basically a number on the webpage representing volume.

i used this code here:

driver.get('https://dexscreener.com/ethereum/' + str(tokenadress))
try:
    fivemVolume = WebDriverWait(driver, delay).until(EC.presence_of_element_located(
        (By.XPATH,         '/html/body/div[1]/div/main/div/div[2]/div/div[2]/div/div/div[1]/div[4]/div[2]/div[1]/div[1]/div[2]/span[2]')))
except:
   #more codee

I think its something to do with the webpage loading into some iframe as a default but when i added this code it didn't help:

driver.switch_to.default_content()
3
  • Temporarily remove the try/except statements and just call the code directly. Then we can at least see what the exception is. Commented Dec 17, 2022 at 20:45
  • And could you share an screenshot of the element you want to use? Commented Dec 17, 2022 at 20:49
  • yes i shared a screenshot now .help will be greatly appreciated. Commented Dec 18, 2022 at 23:40

1 Answer 1

0

Your locator do not match any element on that page.
Elements you trying to access are inside iframe.
So, you need first to switch into the iframe.
The following code should work but I had problems running Selenium on that page since it is blocked by cloudflare:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 30)

url = "https://dexscreener.com/ethereum/0x1a89ae3ba4f9a97b10bac6a77061f00bb956858b"
driver.get(url)

wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id*='tradingview']")))

value = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-name='legend-source-item'] [class='valueItem-1WIwNaDF'] .valueValue-1WIwNaDF"))).text
print(value)
Sign up to request clarification or add additional context in comments.

5 Comments

im getting this error when trying your code: selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
you are right, sorry. Fixed that
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[[id*='tradingview']]"))) is the line thats causing the error ,not the one you corrected. but i think you might be on to something here.
Ah, sure. I'm so sorry. That is because I could not debug it. Fixed now.
so it does work but i was interested in the values located on the right side of the webstie where you can click 5m,30m and 24h statistics. i would greatly appriciate help because im very new to selelnium and iframes.i posted screenshot below

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.