Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import datetime
- import requests
- from fake_useragent import UserAgent
- import csv
- import io
- request = requests.get(url="https://www.sportmaster.ru/catalog/vidy_sporta_/plavanie/ochki_dlya_plavaniya/")
- page = BeautifulSoup(request.text, 'lxml')
- product_cards = page.find_all("div", class_="sm-product-card")
- for product_card in product_cards:
- title = product_card.find("a", class_ = "sm-link").text.strip()
- price_new = product_card.find("div", class_="price").find('span', class_="sm-amount__value").text.replace(" ", "").strip()
- try:
- price_old = product_card.find("div", class_="price").find('span', class_="sm-amount_old").text.replace(" ", "").strip()
- except Exception:
- price_old = "0"
- string = f'{title}, {price_new}, {price_old}'
- with io.open("example.txt", "a", encoding="utf-8") as file:
- file.write(f'{string}\n')
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement