프로그램 분류
파이썬기초127 : 웹크롤링 예제02
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 2,546 조회
- 0 추천
- 목록
본문
import requests
from bs4 import BeautifulSoup
response = requests.get('https://search.naver.com/search.naver?where=post&sm=tab_jum&ie=utf8&query=가로수길원룸')
response.raise_for_status()
#print response.content
# dom : Document Object Model
dom = BeautifulSoup(response.content, 'html.parser')
#print dom
post_elements = dom.select('ul.type01 li.sh_blog_top')
# print len(post_elements)
for post_element in post_elements:
title = post_element.select('a.sh_blog_title')[0].attrs.get('title')
url = post_element.select('a.sh_blog_title')[0].attrs.get('href')
blog_name = post_element.select('a.txt84')[0].text
print(title)
print(url)
print(blog_name)
print '-------------------------------------------------'
"무단배포금지: 클라우드포털(www.linux.co.kr)의 모든 강좌는 저작권에 의해 보호되는 콘텐츠입니다. 무단으로 복제하여 배포하는 행위는 금지되어 있습니다."
관련자료
-
이전
-
다음
댓글 0
등록된 댓글이 없습니다.