python2019. 12. 22. 14:54
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
28
29
30
31
32
33
34
35
import requests
from bs4 import BeautifulSoup
 
 
res = requests.get('https://www.naver.com/')
#res = requests.get('https://easy16.tistory.com/')
 
 
soup= BeautifulSoup(res.content, 'html.parser')
 
 
#Perform a CSS selection operation on the current element.
 
#1,tag 선택
#data = soup.select('div')
 
#2,tag 및 class 선택
#data = soup.select('div.title')
 
#4,class 선택
#data = soup.select('.banner_area')
 
#5,class 계층 선택
#data = soup.select('div.layer_plus._plusAlert strong.tit')
 
#6, id 선택
#data = soup.select('#whale_promotion_banner')
#data = soup.select('form#sfrom')
 
#7, id + class 복합 선택
data = soup.select('div.area_navigation ul#PM_ID_serviceNavi')
 
 
for item in data:
    print(item.get_text())
Posted by easy16