
지니 뮤직 크롤링 했던 것 처럼 무신사 실시간 랭킹을 크롤링 해보려고 하는데 1위만 나오고 안나오네요!
뭐가 문제일까요?
무신사와 다르게 지니 뮤직은 테이블 형식으로 html이 짜여져 있어서 정보를 가져오는 게 수월했던 걸까요?
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
client = MongoClient('mongodb+srv://test:sparta@cluster0.rfofzeu.mongodb.net/Cluster0?retryWrites=true&w=majority')
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.musinsa.com/app/',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
clothes = soup.select('#ranking_goods > div:nth-child(19) > ul')
for clothe in clothes:
a = clothe.select_one('li:nth-child(1) > div.ranking_item_intro > p.txt_tit_brand')
if a is not None:
title = a.text
rank = clothe.select_one('li:nth-child(1) > p').text.strip()
comment = clothe.select_one('li:nth-child(1) > div.ranking_item_intro > p:nth-child(2) > a').text.strip()
image = clothe.select_one('li:nth-child(1) > div.ranking_item_img > a > img')['src']
print(rank, image, title, comment)
