python2019. 12. 24. 17:24
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
import requests
from bs4 import BeautifulSoup
 
soup = BeautifulSoup(res.content,"html.parser")
"""
best_list = soup.select('a._popular_srch_lst_li')
for item in best_list:
    print (item.get_text())
     
"""
"""
#전체 리스트
best_list = soup.select('#popular_srch_lst')
#특정 아이템
best_list = soup.select('#popular_srch_lst > li.on > span.txt > a' )
for item in best_list:
    print (item.get_text())
"""
"""
#best 10.
best_list = soup.select('#popular_srch_lst li a' )
for item in best_list:
    print (item.get_text())
"""
     
#
##productListArea > ul > li:nth-child(1) > p > a
#best_list = soup.select('#cateProductListArea50000000 ul li p a' )
best_list = soup.select('#productListArea > ul > li> p > a' )
 
for item in best_list:
    print (item.get_text())
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
from bs4 import BeautifulSoup
 
soup = BeautifulSoup(res.content,"html.parser")
 
#Naver stocks
##contentarea > div.box_type_l > table > tbody > tr:nth-child(3) > td:nth-child(2) > a
best_list = soup.select('div.box_type_l table  tr' )
 
for item in best_list:
    title=item.find('a')
    tier=item.find('td',class_='no')
    change_list=item.select('td.number > span.tah.p11.nv01')
    #print(change_list)
    #change=change_list[1]
     
     
    if title !=None and len(change_list) > 1:
        print(tier.get_text() + "위 ",title.get_text(),change_list[1].get_text().strip())
         
         
        
Posted by easy16