import requests
from bs4 import BeautifulSoup
def get_cheapest_house_in_szabolcs():
url = "https://ingatlan.com"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
listings = soup.find_all('div', class_='listing-card')
cheapest_price = float('inf')
cheapest_listing = None
for listing in listings:
price_element = listing.find('div', class_='price')
title_element = listing.find('h2', class_='title')
link_element = listing.find('a', href=True)
if price_element and title_element:
price_text = price_element.text.strip().replace(' ', '').replace('Ft', '')
try:
price = float(price_text)
if price < cheapest_price:
cheapest_price = price
cheapest_listing = {
'title': title_element.text.strip(),
'price': f"{cheapest_price:,.0f} Ft",
'link': f"https://ingatlan.com{link_element['href']}" if link_element else "Nincs link"
}
except ValueError:
continue
if cheapest_listing:
print("A legolcsóbb ház Szabolcs-Szatmár-Bereg megyében:")
print(f"Cím/Leírás: {cheapest_listing['title']}")
print(f"Ár: {cheapest_listing['price']}")
print(f"Hirdetés linkje: {cheapest_listing['link']}")
else:
print("Nem található hirdetés.")
except requests.RequestException as e:
print(f"Hiba történt a lekérdezés során: {e}")
if __name__ == "__main__":
get_cheapest_house_in_szabolcs()
Nincsenek megjegyzések:
Megjegyzés küldése