Home > database >  Turning pages using a parser how can you implement it?
Turning pages using a parser how can you implement it?

Time:10-16

I need to write a loop so that the parser collects data from all pages, but my version does not work, how could I implement it differently?

import time 
import pandas as pd
from selenium.webdriver import Chrome
from datetime import datetime


webdriver = r"C:\Users\К.Бояр (Второй)\source\repos\RozetaParcer\chromedriver.exe"

driver = Chrome(webdriver)
driver.implicitly_wait(10)
driver.get("https://rozetka.com.ua/search/?producer=gazer&seller=rozetka&text=Gazer")

total = []
items = driver.find_elements_by_css_selector(".goods-tile.ng-star-inserted")
cur_date = datetime.now().strftime("%d_%m_%Y")
for item in items:
    t_name = item.find_element_by_css_selector('.goods-tile__title').text
    t_price = item.find_element_by_css_selector('.goods-tile__price-value').text
    t_nal = item.find_element_by_css_selector('.goods-tile__availability').text    
    row = cur_date, t_name, t_price, t_nal
    total.append(row)

driver.close()
    
df = pd.DataFrame(total, columns=['Date','Name', 'Price', 'Nal'])
df.to_csv(f'Rozetka_parcer_{cur_date}.csv')

CodePudding user response:

you have to get button with .pagination__direction_type_forward in a while loop until button get disabled and gray ( this means you are at last page ) on that while loop you get items before you click on the next page button
there to many way to approach this but the easiest imo is this ( and this problems its different for every websites because they are different in tech they used and the html they have )

  • Related