Home>

Wrote a parser using Selenium, but after the validation loop it only returns "0", what did I do wrong?

from selenium.webdriver import Chrome
import pandas as pd
import time
webdriver= r "C: \ Users \ K. Boyar (Second) \ source \ repos \ RozetaParcer \ chromedriver.exe" ### put your browser driver's path
driver= Chrome (webdriver)
driver.get ("https://rozetka.com.ua/search/?producer=gazer&
seller= rozetka &
text= Gazer ") ### here the website url
items= len (driver.find_elements_by_class_name ("goods-tile__picture ng-star-inserted")) ### here you put the class name of the HTML element which contains the data to scrap
total= []
for item in range (items):
        items= driver.find_elements_by_class_name ("goods-tile__picture ng-star-inserted")
        for item in items:
            itemName= item.find ('span', class _= 'goods-tile__title'). text.strip ()
            itemPrice= item.find ('span', class _= 'goods-tile__price-value'). text
            itemNal= item.find ('div', class _= 'goods-tile__availability goods-tile__availability -available ng-star-inserted'). text.strip ()
            new= ((cur_data, itemName, itemPrice, itemNal))
            total.append (new)
            cur_data= datetime.now (). strftime ("% d_% m_% Y")
df= pd.DataFrame (total, columns= ['time', 'Name', 'Price', 'Nal'])
df.to_csv ('Rozetka_parcer_ {cur_data} .csv')
print (items)
driver.close ()

I also tried this option:

from selenium.webdriver import Chrome
import pandas as pd
import time
import request
webdriver= r "C: \ Users \ K. Boyar (Second) \ source \ repos \ RozetaParcer \ chromedriver.exe" ### put your browser driver's path
driver= Chrome (webdriver)
driver.get ("https://rozetka.com.ua/search/?producer=gazer&
seller= rozetka &
text= Gazer ") ### here the website url
items= len (driver.find_elements_by_class_name ("goods-tile__picture ng-star-inserted")) ### here you put the class name of the HTML element which contains the data to scrap
total= []
for item in range (items):
        items= driver.find_elements_by_class_name ("goods-tile__picture ng-star-inserted")
        for item in items:
            t_name= item.find_element_by_class_name ('goods-tile__title'). text
            t_price= item.find_element_by_class_name ('ng-star-inserted'). text
            t_nal= item.find_element_by_class_name ('goods-tile__availability goods-tile__availability -available ng-star-inserted'). text
            new= ((cur_data, t_name, t_price, t_nal))
            total.append (new)
            cur_data= datetime.now (). strftime ("% d_% m_% Y")
df= pd.DataFrame (total, columns= ['time', 'Name', 'Price', 'Nal'])
df.to_csv ('Rozetka_parcer_ {cur_data} .csv')
print (items)
driver.close ()

I don’t think the problem is in the webdriver, because when compiling there are no questions to it, it opens a window and goes to the desired site, but it doesn’t pull the data.

then there is no such data

Эникейщик2021-10-13 05:24:27

and a question for thought: if the code finds 10 elements that satisfy the condition, then how many times will the page be parsed?

Эникейщик2021-10-13 05:27:03

How then to introduce classes so that it would detect the data? I tried all the classes and it doesn't work

Константин Николаевич Бояр II2021-10-13 05:35:00