python2019. 12. 17. 23:11
import requests 

from bs4 import BeautifulSoup 

html = requests.get('https://news.naver.com/main/read.nhn?mode=LSD&mid=shm&sid1=100&oid=032&aid=0002981251') 

soup = BeautifulSoup(html.content, "html.parser") 


#h1로 시작하는 첫번째 tag를 가져옴.
#data = soup.find('h1') 
#data = soup.find('p') 
#속성(attr)를 인자로 지정하는 여러가지 방법
#data = soup.find('p', class_='head_channel_layer') 
#data = soup.find('p','head_channel_layer') 
#data = soup.find('p', attrs = { 'class':'head_channel_layer'}) 

data = soup.find(id="articleBodyContents") 

#print(data) 
print(data.get_text())


#리스트 형태로 가져옴
data = soup.find_all('p') 
for item in data: 
    print(item.string)

'python' 카테고리의 다른 글

크롤링 연습 3. select  (0) 2019.12.22
크롤링 연습 2. 실시간 검색어  (0) 2019.12.19
출력 format 예제  (0) 2019.12.08
jupyter note login token 확인 방법  (0) 2019.12.07
try except 문  (0) 2019.11.20
Posted by easy16