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

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

The number of nodes and edges I calculated manually and by a method provided by networkx library dont match

I am trying to analyse a graph using networkx library in Python. I have implemented a function that returns the nodes and edges of that graph. After that I counted the number of nodes and edges by implementing the len() function for nodes and edges, which gave me 17 for both nodes and edges. However, when I used the method graph.number_of_nodes() of networkx library it gave me 53. My code: import pandas as pd import networkx as nx import matplotlib.pyplot as plt header_list = ["a","b","w"] E =pd.read_csv("aves-barn-swallow-contact-network.edges",sep=" ",header= None,names=header_list) # print(E.head()) # prints first few rows of the csv file G = nx.from_pandas_edgelist(E,"a","b",["w"]) nx.draw(G) plt.show() class GraphAnalyse: #finding nodes and edges def nodeEdge(self,Graph): nodes = Graph.nodes() edges = Graph.edges() ...