Skip to content

Instantly share code, notes, and snippets.

@return0927
Created October 17, 2017 16:34
Show Gist options
  • Save return0927/f0831fd7bc8f893422fcd31c696ac92f to your computer and use it in GitHub Desktop.
Save return0927/f0831fd7bc8f893422fcd31c696ac92f to your computer and use it in GitHub Desktop.
음원사이트 "벅스" 에서 차트를 파싱해옵니다.
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = urlopen("http://music.bugs.co.kr/chart/track/day/total?chartdate=20171018")
soup = BeautifulSoup(url, 'lxml')
cnt_artist = 0
cnt_title = 0
for tag in soup.find_all("p", attrs={"class":"artist"}):
cnt_artist += 1
# 아티스트 명에서 2회 중복되는 경우, 첫째 줄의 String 으로 대체
print(cnt_artist, tag.text.strip().split("\n")[0])
print("="*20)
for tag in soup.find_all("p", attrs={"class":"title"}):
cnt_title += 1
# 아티스트 명에서 데이터 이탈을 발견하여 혹시 모를 줄 분리 처리
print(cnt_title, tag.text.strip().split("\n")[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment