위 이미지처럼 결과값 도출하기
지난 개발일지에서(링크텍스트) 조금 더 응용한 과정연습!
1.먼저 순서에 커서 올린 후 copy selector하기
#old_content > table > tbody > tr:nth-child(2) > td:nth-child(1) > img
2.평점에 커서 올린 후 copy selector하기
#old_content > table > tbody > tr:nth-child(2) > td.point
예시)
for tr in trs:
a_tag = tr.select_one('td.title > div > a')
//tr값에서 따오는 것이므로 고정!
if a_tag is not None:
//순서는 "alt=01" 이렇게 있으므로 alt추출
rank = tr.select_one('td:nth-child(1) > img')['alt']
title = a_tag.text
star = tr.select_one('td.point').text //평점은 .text로 텍스트값 추출!
print(rank,title,star)
내가 한 복잡한 예시)
tr값에 다 하나하나 지정해두어 조금 복잡해졌지만 스스로 하나하나 해서 뿌듯!!
for tr in trs:
a_rank = tr.select_one('img')
a_title = tr.select_one('td.title > div > a')
a_point = tr.select_one('td.point')
if a_title is not None:
title = a_title.text
number = a_rank['alt']
point = a_point.text
print(number,title,point)