easymc.io 网络抓取绑定以提取值

easymc.io web scraping tying to extract a value

我正在尝试获取尽可能多的 easymc.io 帐户密钥,我尝试获取按钮的值但它没有,当我试图找到 element_by_xpath 它说 xpath 不存在

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

CHROMEDRIVER_PATH = 'C:\Users\Downloads\chromedriver_win\chromedriver.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')

要抓取 accounts keys 的值,例如8yBAnUFoNlj3JJHzFE7t 你需要诱导 for the visibility_of_element_located() and you can use either of the following :

  • 使用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"))
    
  • 使用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"))
    
  • 控制台输出:

    8yBAnUFoNlj3JJHzFE7t
    
  • 注意:您必须添加以下导入:

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

参考资料

您可以在 中找到一些相关讨论: