커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
크롤링
undefined주차
북마크
오*은
댓글
8
추천
0
조회수
25
조회수
25
답변 완료

다시 질문 올립니다! 여기서 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)
취소
 공유
취소
댓글 0
댓글 알림
나의얼굴