# Python Web Scraping

# Title : Quiz
# Date : 2020-09-09
# Creator : nadocoding

# ######### Sample #########
# =========== 매물 1 ===========
# 거래 :   월세
# 면적 :   109/84  (공급/전용)
# 가격 :   30,000/240  (만원)
# 동　 :   206동
# 층　 :   고/28
# =========== 매물 2 ===========
#    ...
# ##########################

import requests
from bs4 import BeautifulSoup

url = "https://search.daum.net/search?nil_suggest=btn&w=tot&DA=SBC&q=%EC%86%A1%ED%8C%8C+%ED%97%AC%EB%A6%AC%EC%98%A4%EC%8B%9C%ED%8B%B0"
res = requests.get(url)
res.raise_for_status()
soup = BeautifulSoup(res.text, "lxml")

# with open("quiz.html", "w", encoding="utf8") as f:
#     f.write(soup.prettify())

data_rows = soup.find("table", attrs={"class": "tbl"}).find(
    "tbody").find_all("tr")
for index, row in enumerate(data_rows):
    columns = row.find_all("td")

    print("=========== 매물 {} ===========".format(index+1))
    print("거래 :", columns[0].get_text().strip())
    print("면적 :", columns[1].get_text().strip(), "(공급/전용)")
    print("가격 :", columns[2].get_text().strip(), "(만원)")
    print("동 :", columns[3].get_text().strip())
    print("층 :", columns[4].get_text().strip())
