본문 바로가기

Python_Crawling

(28)
190224> Python-NaverNews 사진 + 뉴스 제목 + 요약 + 제공자 크롤링 Q. 네이버 뉴스 중 속보에 해당하는 사진 + 뉴스 제목 + 요약 + 제공자를 크롤링 해보자. A.import requests from bs4 import BeautifulSoup r = requests.get("https://news.naver.com/main/list.nhn?mode=LSD&mid=sec&sid1=100") c = r.content soup = BeautifulSoup(c, "html.parser") all=soup.find("ul",{"class":"type06_headline"}) # print(all) all2 = all.find_all(."li") # print(all2[0]) for item in all2: try: img = item.find("dt",{"class":"ph..
190224> Python-Naver News 크롤링 Q. 네이버 메뉴 중 색칠 칠한 뉴스란을 크롤링해보자. A.import urllib.request import bs4 url = "https://www.naver.com/" html = urllib.request.urlopen(url) bs_obj = bs4.BeautifulSoup(html, "html.parser") ul = bs_obj.find("ol", {"class":"ca_l"}) lis = ul.findAll("li") for li in lis: a = li.find("a") O.소식통 "김정은 전용열차, 톈진역 통과해 남행 관측"北美 하노이 의제협상팀, 정상회담 'D-3' 맞아 '숨고르기'4대강 보 해체 논란…"900억 들여 해체?"vs"유지비 1천700억""'환경부 블랙리스트' 보은성 인..
190224> Python-Naver Menu 크롤링 Q. Q-1. 메일 / 카페 / 블로그 / 지식in / 쇼핑 / 네이버페이 / 네이버티비Q-2. 사전 / 뉴스 / 증권 / 부동산 / 지도 / 영화 / 뮤직 / 책 / 웹툰네이버 상기 메뉴를 크롤링 해보자. A.A-1.import urllib.request import bs4 url = "https://www.naver.com/" html = urllib.request.urlopen(url) bs_obj = bs4.BeautifulSoup(html, "html.parser") ul = bs_obj.find("ul", {"class":"an_l"}) lis = ul.findAll("li") for li in lis: a_tag = li.find("a") span = a_tag.find("span",{"cl..
190224> Python-M.NET 차트 순위 crawling Q.엠넷 차트 순위를 크롤링 하여 목록화 / 이미지를 다운받자. A.import bs4 import requests def save_image(img_url, date, rank, title, artist): response = requests.get(img_url) content = response.content filename = "{}\\{:03}_{}_{}.jpeg".format(date, rank, title, artist) file = open(filename,"wb") file.write(content) date = input("검색할 날짜[YYYYmmdd]를 입력하세요 : ") pages = int(input("총 몇 페이지를[50/page]를 크롤링할까요 : ")) charts = [] ..