1. BeautifulSoup 모듈 설치
pip install beautifulsoup4
2. 네이버의 요일별 웹툰 리스트 가져오기
from urllib.request import urlopen
from bs4 import BeautifulSoup
# naver 일요 웹툰 전체 리스트 가져오기
url = "https://comic.naver.com/webtoon/weekdayList.nhn?week=mon"
with urlopen(url) as html:
urlopen(url)
src = html.read()
soup = BeautifulSoup(src, "html.parser")
# print(soup.prettify())
img_ul = soup.find("ul", {"class": "img_list"})
img_list = img_ul.find_all("dl")
for img in img_list:
title = img.dt.a.get_text()
auth = img.find("dd", {"class": "desc"}).a.get_text()
rate = img.find("div", {"class": "rating_type"}).strong.get_text()
print('제목:', title, end = ', ')
print('작가:', auth, end = ', ')
print('평점:', rate)
참고 : https://www.crummy.com/software/BeautifulSoup/bs4/doc/
Beautiful Soup Documentation — Beautiful Soup 4.4.0 documentation
Non-pretty printing If you just want a string, with no fancy formatting, you can call unicode() or str() on a BeautifulSoup object, or a Tag within it: str(soup) # ' I linked to example.com ' unicode(soup.a) # u' I linked to example.com ' The str() functio
www.crummy.com
https://wayhome25.github.io/python/2017/04/25/cs-27-crawling/
파이썬 크롤링 (beautifulsoup, selenium 활용) · 초보몽키의 개발공부로그
패스트캠퍼스 컴퓨터공학 입문 수업을 듣고 중요한 내용을 정리했습니다. 개인공부 후 자료를 남기기 위한 목적임으로 내용 상에 오류가 있을 수 있습니다.
wayhome25.github.io
'프로그래밍 > PYTHON' 카테고리의 다른 글
맥 파이썬 개발환경 (with pyenv) (0) | 2019.09.15 |
---|
댓글