easymc.io web scraping tying to extract a value

Tags: , , , ,



I’m trying to get as many easymc.io accounts keys as I can, I tried to get the value of a button but it doesn’t and when I’m trying to find the element_by_xpath it says that the xpath does not exist

#from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

CHROMEDRIVER_PATH = 'C:\Users\Downloadschromedriver_winchromedriver.exe'
options = Options()
options.headless = False
driver = webdriver.Chrome(CHROMEDRIVER_PATH, options=options)
driver.get('https://easymc.io/get?new')
element = driver.find_element_by_xpath('//*[@id="root"]/div[2]/div[1]/div[2]/div/div[2]/div[2]/div/div[2]/div[2]/div/input')

Answer

To scrape the value of the accounts keys e.g. 8yBAnUFoNlj3JJHzFE7t you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://easymc.io/get?new')
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input.form-control[aria-label='Alt Token']"))).get_attribute("value"))
    
  • Using XPATH:

    driver.get('https://easymc.io/get?new')
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@class='form-control' and @aria-label='Alt Token']"))).get_attribute("value"))
    
  • Console Output:

    8yBAnUFoNlj3JJHzFE7t
    
  • Note : You have to add the following imports :

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

References

You can find a couple of relevant discussions on NoSuchElementException in:



Source: stackoverflow