매우 기초적인 예제지만 재밌었다. 기초 문법에서 평균내는건 아무런 감흥이 없었는데 +_+
가우스 전자
평점 구하기
import requests
from bs4 import BeautifulSoup
url = "https://comic.naver.com/webtoon/list.nhn?titleId=675554"
res = requests.get(url)
res.raise_for_status()
soup = BeautifulSoup(res.text, "lxml")
# cartoons = soup.find_all("td", attrs={"class":"title"})
# title = cartoons[0].a.get_text()
# link = cartoons[0].a["href"]
# print(title)
# print("https://comic.naver.com" + link)
# 만화 제목 + 링크 가져오기
# for cartoon in cartoons:
# title = cartoon.a.get_text()
# link = "https://comic.naver.com" + cartoon.a["href"]
# print(title, link)
# 평점 구하기
total_rates = 0
cartoons = soup.find_all("div", attrs={"class":"rating_type"})
for cartoon in cartoons:
rate = cartoon.find("strong").get_text()
print(rate)
total_rates += float(rate)
print("전체 점수 : ", total_rates)
print("평균 점수 : ", total_rates / len(cartoons))
'활용3. 웹스크래핑(0825-0829) > requests' 카테고리의 다른 글
스크래핑 2-3 네이버 주식 (csv 모듈 ) (0) | 2022.08.28 |
---|---|
스크래핑 2-2 다음 영화 이미지 저장( requests ) (0) | 2022.08.28 |
스크래핑 2-1 쿠팡 (User-Agent 헤더) (0) | 2022.08.28 |
스크래핑 0. 기초 requests, headers , re, BeautifulSoup (0) | 2022.08.25 |
댓글