
다시 질문 올립니다! 여기서 nth-child(1)를 수정해야 된다고 하셨는데요.
감이 잘 안 잡혀서 어떻게 수정해야 하는지 여쭤봅니다.
변수를 설정하여 count += 1 씩 증가시켜 순위를 바꿔줘야 하는 걸까요?
아니면 nth-child(1) 에 1만 변경할 수 있는 다른 방법이 있을까요?
답변 부탁드립니다! 🙏
import requests
from bs4 import BeautifulSoup
url = 'https://www.musinsa.com/ranking/best'
response = requests.get(url)
if response.status_code == 200:
html = response.text
soup = BeautifulSoup(html, 'html.parser')
ul = soup.select_one('#goodsRankList')
titles = ul.select('p.item_title > a')
rank = ul.select_one('li:nth-child(1) > p').text[0:20].strip()
image = ul.select_one('div.li_inner > div.list_img > a > img')['data-original']
comment = ul.select_one('p.list_info > a').text.strip()
for title in titles:
print(rank, title.text, image, comment)
else :
print(response.status_code)
