https://cafe.naver.com/startcodingofficial/1473
너무나너무나 힘들었던 KB 통계 자료실 😡😡😡
안녕하세요!!!!!! 3시쯤 완성했는데, 친구랑 통화하느라.... 어우..... 저녁 6시 반쯤?? 오늘은 무엇을 하면서 실습해볼까~ 하다가! 주말인가.. 요 며칠전에, 나오...
cafe.naver.com
선택자.click() 가 안 먹혀서 꽤나 고생했다😡
나머지는 그렇게 어렵지 않았는데!!
50개월치 210개를 자동 다운로드 !!
이제 클릭 한번이면,
2006년 2월 처음 자료부터 지금까지 싸그리 모아올 수가 있다!
너무나 새롭고 신기하고 놀라운 파이썬 😆😆😆
▼ 저장한 파일 목록

wanna = int(input('몇 개월 치?'))
url = 'https://kbland.kr/pages/kbStatistics.html'
driver = webdriver.Chrome()
driver.implicitly_wait(2)
driver.get(url)
driver.maximize_window()
driver.implicitly_wait(2)
# iframe 변경 후 '주간아파트'탭 이동
driver.switch_to.frame(0)
driver.find_element(By.CSS_SELECTOR, '#__BVID__28__BV_tab_controls_ > li:nth-of-type(1)').click()
xxx = [] # 없는 주 체크 리스트
actions = ActionChains(driver)
count = 0
while count < wanna :
count += 1
# 전 달로 넘기기
next = driver.find_element(By.CSS_SELECTOR, '.mx-icon-left')
driver.execute_script("arguments[0].click();", next)
time.sleep(1)
# 중간에 보고서 없는 주의 월요일 날짜 출력 (연휴 등)
try:
disabled = driver.find_element(By.CSS_SELECTOR, '.mx-date-row > .cell.disabled:nth-of-type(2):not(.not-current-month)').get_attribute('title')
xxx.append([disabled])
except:
pass
# 각 달마다 6주까지 클릭 후 파일 다운
for i in range (2,7):
# i 행이 비활성화 되어있으면 패스
if 'not' in driver.find_element(By.CSS_SELECTOR, f'div.mx-calendar-content > table > tbody > tr:nth-of-type({i}) > td:nth-of-type(2)').get_attribute('class'):
pass
elif 'disabled' in driver.find_element(By.CSS_SELECTOR, f'div.mx-calendar-content > table > tbody > tr:nth-of-type({i}) > td:nth-of-type(2)').get_attribute('class'):
pass
else:
week = driver.find_element(By.CSS_SELECTOR, f'.mx-calendar-content > table > tbody > tr:nth-of-type({i}) > td:nth-of-type(2)')
driver.execute_script("arguments[0].click();", week)
time.sleep(1)
driver.find_element(By.XPATH, "//button[contains(@class, 'btn btn-download icoType3') and contains(text(), '주간통계표')]").click()
time.sleep(0.5)
# 각 월의 첫번째 주
if 'not' in driver.find_element(By.CSS_SELECTOR, f'div.mx-calendar-content > table > tbody > tr:nth-of-type(1) > td:nth-of-type(2)').get_attribute('class') :
pass
else:
week = driver.find_element(By.CSS_SELECTOR, f'.mx-calendar-content > table > tbody > tr:nth-of-type(1) > td:nth-of-type(2)')
driver.execute_script("arguments[0].click();", week)
time.sleep(1)
driver.find_element(By.XPATH, "//button[contains(@class, 'btn btn-download icoType3') and contains(text(), '주간통계표')]").click()
time.sleep(0.5)
df = pd.DataFrame(xxx, columns=['출력 못한 날짜'])
df.to_excel('C:/Users/inhye/Downloads/출력 못 한 날짜.xlsx')
print(f'{count}개월 데이터 추출 완료')
'파이썬 코딩' 카테고리의 다른 글
2024.12.14. [파이썬] 네이버 스토어 상품 크롤링 GUI (0) | 2025.01.15 |
---|---|
2024.12.13. [파이썬] 쿠팡 상품 크롤링 GUI (0) | 2025.01.15 |
2024.12.07. [파이썬] 네이버 지도 크롤링 (0) | 2025.01.15 |
2024.12.05. [파이썬] DART 기업개황 크롤링 (0) | 2025.01.15 |
2024.12.03. [파이썬] SRT 조회하기 (0) | 2025.01.15 |