etc / / 2021. 1. 26. 22:14

파이썬 뷰티풀숩 beautifulsoup 이용한 멜론 차트 크롤링 가져오기

구글에서 파이썬 최신버전 다운하신뒤 

 

 

pip install bs4를 이용하여 beautifulsoup 다운로드

 

 

 

import urllib.request

from bs4 import BeautifulSoup

 

f= open("test.txt""w",encoding="utf-8")

 

h= {'user-Agent':'Mozilla/5.0'}

url = "https://www.melon.com/chart/index.htm"

 

req=urllib.request.Request(url,headers=h)

a=urllib.request.urlopen(req)

 

b=a.read().decode('utf-8')

 

soup = BeautifulSoup(b,'html.parser')

 

c= soup.find_all(class_="rank01"#찾을 클래스

print(c)

 

for n in c:

    f.write(str(n)) #저장

 

f.write(b)

f.close

 

 

 

 

 

 

 

import urllib.request

from bs4 import BeautifulSoup

 

f= open("test.txt""w",encoding="utf-8")

 

h= {'user-Agent':'Mozilla/5.0'}

url = "https://www.melon.com/chart/index.htm"

 

req=urllib.request.Request(url,headers=h)

a=urllib.request.urlopen(req)

 

b=a.read().decode('utf-8')

 

soup = BeautifulSoup(b,'html.parser')

 

c= soup.find_all(class_="rank01"#찾을 클래스

print(c)

 

for n in c:

    f.write(str(n.get_text())) #저장

 

f.write(b)

f.close

 

#n.get_text() 추가

 

 

 

 

 

 

import urllib.request

from bs4 import BeautifulSoup

 

f= open("test.txt""w",encoding="utf-8")

 

h= {'user-Agent':'Mozilla/5.0'}

url = "https://www.melon.com/chart/index.htm"

 

req=urllib.request.Request(url,headers=h)

a=urllib.request.urlopen(req)

 

b=a.read().decode('utf-8')

 

soup = BeautifulSoup(b,'html.parser')

 

c= soup.find_all(class_="rank01"#찾을 클래스



for n in c:

    f.write(str(n.get_text())) #저장



f.close

 

  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유