Multiple page table data is not saved in Selenium! Only the data of the last web page table is being saved
**
import pandas as pd
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
for c in range(1, 19):
linkall = f'https://www.coingecko.com/?page={c}'
driver = webdriver.Chrome()
driver.get(linkall)
elem = driver.find_element(By.TAG_NAME, 'table')
head = elem.find_element(By.TAG_NAME, 'thead')
body = elem.find_element(By.TAG_NAME, 'tbody')
list_rows = []
for items in body.find_elements(By.TAG_NAME, 'tr'):
list_cells = []
for item in items.find_elements(By.TAG_NAME, 'td'):
list_cells.append(item.text)
list_rows.append(list_cells)
driver.close()
print(list_rows)
print(len(list_rows))
df = pd.DataFrame(list_rows)
df.to_csv('coingecko.csv')
**
** MY output of terminal in down blow: ** [['', '1', 'Bitcoin\nBTC', '$17,172.49', '-0.4%', '-0.1%', '1.5%', '$14,619,270,364'............... 100 [['', '101', 'BitDAO\nBIT', '$0.309701', '-0.7%', '0.6%', '1.2%', '$6,315,202', '$333,824,690'...... 100 [['', '201', 'PlayDapp\nPLA', '$0.233737', '1.8%', '12.6%', '12.9%', '$84,898,280', '$125,118,...... 100 ............The remaining 16 like this, a total of 19 are the output of the table scraping of the web page.
Here I want to scrape multiple web pages table data by python selenium. But I have only got last web page table data. There are 19 webpage . Each web page have 100 rows. 19*100 = 1900. But I have only get 100 rows of last page. When scraping here, the data of all web pages are scraped and shown in the terminal! But the data of 19 web pages is not saved in my csv file! Only the data of the last 1 web page has been saved! I want to save all desired 19 web pages data serially in csv file! Where did my code go wrong? Did I have mistake to append? Please experts correct me! Prepare me such a code! As if I get 1900 rows of 19 web pages serially!
source https://stackoverflow.com/questions/74764594/multiple-page-table-data-is-not-saved-in-selenium-only-the-data-of-the-last-web
Comments
Post a Comment