From 0de563e86534e8764f8742decabc484f6f3913dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=B2=D1=88=D0=B0=D0=BD=20=D0=98=D1=81=D0=BC?= =?UTF-8?q?=D0=B0=D0=B8=D0=BB=D0=BE=D0=B2?= Date: Sun, 27 Oct 2024 20:49:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=97=D0=A3=20=D1=81=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D0=BF=D0=BF=D0=B8=D1=82=20(=D0=B1=D0=B5=D1=80=D1=91=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=B2=D1=81=D1=8F=20=D0=B8=D0=BD=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BE=D0=B1=20=D0=9E?= =?UTF-8?q?=D0=97=D0=A3)=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=20=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=20=D0=9E=D0=97=D0=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scraping/scrapingMain.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 scraping/scrapingMain.py diff --git a/scraping/scrapingMain.py b/scraping/scrapingMain.py new file mode 100644 index 0000000..8e96265 --- /dev/null +++ b/scraping/scrapingMain.py @@ -0,0 +1,43 @@ +from selenium import webdriver +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from webdriver_manager.chrome import ChromeDriverManager + +# Инициализация драйвера +driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) + +# URL страницы товара +url = 'https://www.citilink.ru/catalog/noutbuki/?ref=mainpage' + +# Переход на страницу +driver.get(url) + +try: + # Ожидание появления хотя бы одного элемента
  • с указанным классом + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.CSS_SELECTOR, 'li.app-catalog-12y5psc.e4qu3682')) + ) + + # Поиск всех элементов
  • с указанным классом + all_elements = driver.find_elements(By.CSS_SELECTOR, 'li.app-catalog-12y5psc.e4qu3682') + + # Список для хранения информации об оперативной памяти + ram_info_list = [] + + # Фильтрация элементов по тексту + for element in all_elements: + span_element = element.find_element(By.TAG_NAME, 'span') # Ищем внутри
  • + if "Оперативная память" in span_element.text: + ram_info_list.append(element.text) # Добавляем текст элемента в список + + # Вывод информации об оперативной памяти + for ram_info in ram_info_list: + print(f'Информация об оперативной памяти: {ram_info}') + +except Exception as e: + print(f'Ошибка: {e}') +finally: + # Закрытие драйвера + driver.quit()