웹 자동화웹에서 데이터 얻기Beautiful Soup 라이브러리
멜론의 경우
조회 666
좋아요 0
2021년 6월 15일
jaehyunjo
0
채택된 답변 수 2,645
1
댓글 2개
댓글 2개
import requests
import urllib.request
from bs4 import BeautifulSoup
from openpyxl import Workbook
#엑셀파일 생성
#wb = Workbook()
#wb = Workbook(write_only=True)#이 경우에는 쓰기만 함
header01 = {'User-Agent' : 'Mozilla/5.0'}
url='https://www.melon.com/chart/month/index.htm'
modi01=urllib.request.Request(url,headers=header01)
response=urllib.request.urlopen(modi01).read()
#response=requests.get(url)#퍼 오고자 하는 URL 서버에 REQUESTS를 보냄
soup=BeautifulSoup(response,'html.parser')
print(soup)
#wb.save('멜론 {}년 {}월 TOP100 차트.xlsx'.format(year,month))#엑셀파일 저장