일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 5주차
- 위키백과
- NoSQL
- 4주차
- nginx
- 스파르타코딩클럽
- HTTPS
- Node.js
- db
- 3주차
- 부트스트랩
- OpenAPI
- 2주차
- SQL
- cors
- 트랜잭션
- 숙제
- post
- Transaction
- Sequelize
- node winston
- 1주차
- Get
- MongoDB
- 개발일지
- 웹 스크래핑(크롤링)
- 비동기
- 항해99
- 노드 윈스턴
- JWT
Archives
- Today
- Total
얼음꽃의 일지
지니 뮤직 크롤링하기 본문
728x90
- 배운 내용을 가지고 만든 부분이기 때문에 따로 설명 없이 올려놓겠습니다.
import requests
from bs4 import BeautifulSoup
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?ditc=M&rtm=N&ymd=20210701',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.info > a.title.ellipsis 곡제목
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.number 순위
#body-content > div.newest-list > div > table > tbody > tr:nth-child(1) > td.info > a.artist.ellipsis 가수
musics = soup.select('#body-content > div.newest-list > div > table > tbody > tr')
for music in musics:
rank = music.select_one('td.number').text[0:2].strip()
title = music.select_one('td.info > a.title.ellipsis').text.strip()
artist = music.select_one('td.info > a.artist.ellipsis').text
print(rank, title, artist)
결과입니다.
728x90
'웹개발 개발일지 > 3주차' 카테고리의 다른 글
DB 설명 및 사용 (1) | 2022.09.01 |
---|---|
웹 스크래핑(크롤링) (0) | 2022.09.01 |
패키지 설치 및 패키치를 이용한 간단한 코드 (0) | 2022.09.01 |
DB를 하기에 앞서.. (0) | 2022.08.31 |