본문 바로가기
-------------코딩-------------/Python 기초 코딩

벅스 일간차트 크롤링

by 탶선 2020. 2. 8.
반응형
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>
반응형

'-------------코딩------------- > Python 기초 코딩' 카테고리의 다른 글

네이버 증권뉴스 크롤링(1)  (0) 2020.07.27
python 별찍기 (다이아몬드)  (0) 2020.03.18
별찍기(직각삼각형)  (0) 2020.02.08
별찍기(정사각형)  (0) 2020.02.08
숫자야구 게임  (0) 2020.02.08

댓글