Advertisement
1nikitas

Untitled

May 22nd, 2022
783
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from bs4 import BeautifulSoup
  2. import datetime
  3. import requests
  4. from fake_useragent import UserAgent
  5. import csv
  6. import io
  7.  
  8. request = requests.get(url="https://www.sportmaster.ru/catalog/vidy_sporta_/plavanie/ochki_dlya_plavaniya/")
  9. page = BeautifulSoup(request.text, 'lxml')
  10.  
  11. product_cards = page.find_all("div", class_="sm-product-card")
  12.  
  13. for product_card in product_cards:
  14.     title = product_card.find("a", class_ = "sm-link").text.strip()
  15.     price_new = product_card.find("div", class_="price").find('span', class_="sm-amount__value").text.replace(" ", "").strip()
  16.     try:
  17.         price_old = product_card.find("div", class_="price").find('span', class_="sm-amount_old").text.replace(" ", "").strip()
  18.     except Exception:
  19.         price_old = "0"
  20.  
  21.     string = f'{title}, {price_new}, {price_old}'
  22.  
  23.     with io.open("example.txt", "a", encoding="utf-8") as file:
  24.         file.write(f'{string}\n')
  25. file.close()
Advertisement
RAW Paste Data Copied
Advertisement