import json
import requests
from bs4 import BeautifulSoup
def wr_json(lst: list):
with open('save.json', 'w', encoding='utf-8') as f:
json.dump(lst, f, indent=4, ensure_ascii=False)
URL = 'https://krisha.kz/prodazha/kvartiry/'
HOST = 'https://krisha.kz'
def get_html(url, params=None):
r = requests.get(url, params=params)
return r
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
title = soup.find_all('a', class_='a-card__title')
cards = []
for title in title:
cards.append({'price': title.find('div', class_='offer__price'),
'Floor': title.find('div', class_='offer__advert-short-info'),
'Square': title.find('div', class_='offer__advert-short-info'),
'State': title.find('div', class_='offer__advert-short-info'),
'Construction year': title.find('div', class_='offer__advert-short-info'),
'Conplex Home': title.find('div', class_='offer__advert-short-info'),
'Seller Description': title.find('div', class_='offer__parameters'),
'Description': title.find('div', class_='a-text a-text-white-spaces')})
return cards
def parser():
html = get_html(URL)
if html.status_code == 200:
cards = []
for page in range(1,):
print(f'Парсим страницу: {page}')
html = get_html(URL, params={'page': page})
cards.extend(get_content(html.text))
print(cards)
wr_json(cards)
else:
print('Error')
parser()
Всем привет,можете ли вы помочь где тут я ошибся? Ну впринципе я знаю где тут ошибка a-card__title,не могу спарсить ссылку
import requests
from bs4 import BeautifulSoup
def wr_json(lst: list):
with open('save.json', 'w', encoding='utf-8') as f:
json.dump(lst, f, indent=4, ensure_ascii=False)
URL = 'https://krisha.kz/prodazha/kvartiry/'
HOST = 'https://krisha.kz'
def get_html(url, params=None):
r = requests.get(url, params=params)
return r
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
title = soup.find_all('a', class_='a-card__title')
cards = []
for title in title:
cards.append({'price': title.find('div', class_='offer__price'),
'Floor': title.find('div', class_='offer__advert-short-info'),
'Square': title.find('div', class_='offer__advert-short-info'),
'State': title.find('div', class_='offer__advert-short-info'),
'Construction year': title.find('div', class_='offer__advert-short-info'),
'Conplex Home': title.find('div', class_='offer__advert-short-info'),
'Seller Description': title.find('div', class_='offer__parameters'),
'Description': title.find('div', class_='a-text a-text-white-spaces')})
return cards
def parser():
html = get_html(URL)
if html.status_code == 200:
cards = []
for page in range(1,):
print(f'Парсим страницу: {page}')
html = get_html(URL, params={'page': page})
cards.extend(get_content(html.text))
print(cards)
wr_json(cards)
else:
print('Error')
parser()
Всем привет,можете ли вы помочь где тут я ошибся? Ну впринципе я знаю где тут ошибка a-card__title,не могу спарсить ссылку