배운 것/Python
[Python] 크롤링 기초_네이버 실검 파싱해오기
ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ!
2017. 8. 11. 00:24
1 2 3 4 5 6 7 8 9 10 11 12 13 | from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("https://www.naver.com/").read() #내용 불러옴 soup = BeautifulSoup(html, "html.parser") myUrls = soup.select('span.ah_k')#span태그중 class값이 ah_k인 태그를 셀렉터로 지정 cnt = 0 #횟수를 세기위한 변수 for j in myUrls: cnt+=1 print(str(cnt)+". "+j.text) if cnt==10:#10위까지 파싱하므로 break | cs |
이 코드를 실행시키기 위해서는 requests모듈과 beautifulsoup4가 필요하다.