python2019. 12. 17. 23:11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
 
from bs4 import BeautifulSoup
 
 
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