Skip to main content

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

Popular posts from this blog

Where and how is this Laravel kernel constructor called? [closed]

Where and how is this Laravel kernel constructor called? public fucntion __construct(Application $app, $Router $roouter) { } I have read the documentation and some online tutorial but I can find any clear explanation. I am learning Laravel and I am wondering where does this kernel constructor receives its arguments from. "POSTMOTERM" CLARIFICATION: Here is more clarity.I have checked the boostrap/app.php and it is only used for boostrapping the interfaces into the container class. What is not clear to me is where and how the Kernel class is instatiated and the arguments passed to the object calling the constructor.Something similar to; obj = new kernel(arg1,arg2) or, is the framework using some magic functions somewhere? Special gratitude to those who burn their eyeballs and brain cells on this trivia before it goes into a full blown menopause alias "MARKED AS DUPLICATE". To some of the itchy-finger keyboard warriors, a.k.a The mods,because I believe in th...

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype