Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- getpost
- 장고
- 스파르타코딩
- db네이밍규칙
- 파이썬
- Python
- JPA
- 스파르타코딩클럽
- 겟메핑
- 포스트메핑
- 패스트캠퍼스
- 포링키
- tableperclass
- 리콰이어먼츠 설정
- db설계방법
- 프라이머리키
- 코딩
- 자기계발회고
- jakartapersistenceapi
- 데이터베이스설계요약
- 내일배움캠프
- 팀스파르타
- jpa플러시
- django
- db설계핵심요약
- spring필수문법
- db설계과정
- 릴레이션십데이터베이스
- 데이터베이스네이밍규칙
- dbnamingrule
Archives
- Today
- Total
당우 일기장
지니뮤직 크롤링 하기 본문
파이썬을 이용해 지니뮤직 차트를 크롤링해 보았습니다
탑 50까지의 순위를 크롤링했습니다
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbsparta
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://www.genie.co.kr/chart/top200',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
trs = soup.select('#body-content > div.newest-list > div > table > tbody > tr')
for tr in trs:
title = tr.select_one('td.info > a.title.ellipsis').text.strip()
rank = tr.select_one('td.number').text[0:2].strip()
artist = tr.select_one('td.info > a.artist.ellipsis').text
print(rank, title, artist)