код:
import bs4
import requests
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('lenta')
class Client:
def __init__(self):
self.session = requests.Session()
self.session.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0',
'Accept-Language': 'ru',
}
def load_page(self,page: int = None):
url = 'https://lenta.com/goods-actions/main/#saleday'
res = self.session.get(url=url)
res.raise_for_status()
return res.text
def parse_page(self, text: str):
soup = bs4.BeautifulSoup(text, 'lxml')
container = soup.select('a.promo-item.promo-item--medium')
for block in container:
self.parse_block(block=block)
def parse_block(self, block):
logger.info(block)
logger.info('=' * 100)
def run(self):
self.load_page()
self.parse_page(text='text')
if __name__ == '__main__':
parser = Client()
parser.run()
Ошибка:
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): lenta.com:443
DEBUG:urllib3.connectionpool:https://lenta.com:443 "GET /goods-actions/main/ HTTP/1.1" 200 173557
Версия python 3.8