使用硒从网页中检索数据 - 不检索所有数据 [英] Using selenium to retrieve data from webpage - not retrieving all data

查看:17
本文介绍了使用硒从网页中检索数据 - 不检索所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从 coinmarketcap.com 检索数据(硬币名称、价格、硬币市值和流通量),但是当我运行下面的代码时,我只得到 11 个硬币名称.另外,我无法检索其他数据.我尝试了几种选择,但都没有成功.我的目标是将数据存储在数据框中,以便我可以对其进行分析.

I am trying to retrieve data (coin name, price, coinmarket cap and circulating supply) from coinmarketcap.com, but when I run the code below I only get 11 coin names. Plus, I am not able to retrieve other data. I am tried several options, but none successful. My goal is to store the data in a dataframe, so I can analyze it.

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()

推荐答案

试试这个代码行来获取页面上的所有值:

Try this code line to get all the values on page:

cryptos = [name.text for name in driver.find_elements_by_xpath('//td[3]/a[@class="cmc-link" and starts-with(@href, "/currencies/")]//p[@color="text"]')]

这篇关于使用硒从网页中检索数据 - 不检索所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆