# -*- coding: cp949 -*- from bs4 import BeautifulSoup def get_html(): with open('melon_weekly.html', 'r') as f: html = f.read() return html def extract_chart(): html = get_html() # 저장된 파일을 사용합니다. # BeautifulSoup 로 파싱 soup = BeautifulSoup(html) # div 태그 중 id가 top50, top100인 것을 찾아냄 top50 = soup.find('div', id='top50') top100 = soup.find('div', id='top100') with open('top50.html', 'w') as f: f.write(top50.prettify().encode('utf-8')) with open('top100.html', 'w') as f: f.write(top100.prettify().encode('utf-8')) if __name__ == '__main__': extract_chart()