【发布时间】:2020-12-13 18:32:58
【问题描述】:
我正在尝试从 coinmarketcap.com 检索数据(硬币名称、价格、硬币市值和流通供应量),但是当我运行下面的代码时,我只得到 11 个硬币名称。另外,我无法检索其他数据。我尝试了几种选择,但都没有成功。我的目标是将数据存储在数据框中,以便进行分析。
driver = webdriver.Chrome(r'C:\Users\Ejer\PycharmProjects\pythonProject\chromedriver')
driver.get('https://coinmarketcap.com/')
Crypto = driver.find_elements_by_xpath("//div[contains(concat(' ', normalize-space(@class), ' '), 'sc-16r8icm-0 sc-1teo54s-1 lgwUsc')]")
#price = driver.find_elements_by_xpath('//td[@class="cmc-link"]')
#coincap = driver.find_elements_by_xpath('//td[@class="DAY"]')
CMC_list = []
for c in range(len(Crypto)):
CMC_list.append(Crypto[c].text)
print(CMC_list)
#driver.get('https://coinmarketcap.com/')
#print([my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//table[contains(@class, 'cmc-table')]//tbody//tr//td/a//p[@color='text']")))[:50]])
driver.close()
【问题讨论】:
标签: python selenium web-scraping