Using selenium to retrieve data from webpage - not retrieving all data

醉酒当歌 提交于 2021-01-20 11:28:21

问题


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

回答1:


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"]')]


来源:https://stackoverflow.com/questions/65279203/using-selenium-to-retrieve-data-from-webpage-not-retrieving-all-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!