탶선 2020. 2. 8. 12:58
반응형
from urllib.request import urlopen
from bs4 import BeautifulSoup
from html2text import html2text
import sys
import pprint


if __name__ == "__main__":

    f = open("bugs_chart.txt", "w")

    url = urlopen("http://music.bugs.co.kr/chart/track/day/total")


    bs = BeautifulSoup(url,'html.parser')

    artist_list=[]  # 가수 리스트 생성
    title_list = [] # 제목 리스트 생성
    daily_chart = {} # 가수 + 제목 딕셔너리

    artist = bs.find_all('p', class_='artist', ) #가수 찾기
    title = bs.find_all('p', class_='title')     #제목 찾기

    for title in title:
        title_list.append(title.find('a')['title'])

    count = 0
    for artist in artist:
        artist_list.append(artist.find('a')['title'])
        # print(str(count+1)+'위 '+str(artist_list[count])+' - '+str(title_list[count]))
        daily_chart[count+1] = artist_list[count] + title_list[count]
        count +=1
    daily_chart = pprint.pprint(daily_chart)

    f.write(str(daily_chart))
    f.close()
<pre style='color: rgb(169, 183, 198); font-family: "Courier New"; font-size: 16.5pt; background-color: rgb(43, 43, 43);'>
</pre>
반응형