Sabbir Talukdar
Sabbir Talukdar

Reputation: 33

Using selenium I want to scrape this text

Hello guys I am trying to scrape from this url the following text using selenium: enter image description here But I get the error that it couldnot find any element by that class name.. This is my code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

driver = webdriver.Chrome(r'C:\Users\User\AppData\Local\Programs\Python\Python37\Lib\site-packages\chromedriver_py\chromedriver_win32.exe')
driver.get('https://xangle.io/project/XTZ/full-disclosure')
driver.find_element_by_class_name('fv1').text

Upvotes: 0

Views: 837

Answers (2)

Naveen
Naveen

Reputation: 788

The error is because there are multiple elements with the same class name.

Use XPATH to better traverse the page identify the element required.

WebDriverWait(driver,15).until(EC.visibility_of_element_located((By.XPATH,"//div[contains(@class, 'token-name')]/div[2]")))

driver.find_element_by_xpath("//div[contains(@class, 'token-name')]/div[2]").text

This will give you the Token name text content.

Upvotes: 1

KunduK
KunduK

Reputation: 33384

Induce WebDriverWait() and visibility_of_element_located() and following xpath.

driver.get("https://xangle.io/project/XTZ/full-disclosure")
print(WebDriverWait(driver,15).until(EC.visibility_of_element_located((By.XPATH,"//div[text()='Token Name']/following-sibling::div[1]"))).text)

OR

print(WebDriverWait(driver,15).until(EC.visibility_of_element_located((By.XPATH,"(//div[@class='token-profile-cont']//div[@class='fv1'])[1]"))).text)

Import following libraries.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Upvotes: 1

Related Questions