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 res = requests.get( 'https://search.shopping.naver.com/best100v2/detail.nhn?catId=50000000&listType=B10002' ) 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()) |
'python' 카테고리의 다른 글
크롤링 연습 6. openpyxl 이용 웹 데이터 저장 (0) | 2019.12.25 |
---|---|
크롤링 연습 5. urllib 사용 및 게시판 글 리스트 모두 가져오기 (0) | 2019.12.25 |
크롤링 연습 3. select (0) | 2019.12.22 |
크롤링 연습 2. 실시간 검색어 (0) | 2019.12.19 |
크롤링 연습 1. find, find_all (0) | 2019.12.17 |