파이썬(Python) SBS 최신 뉴스 파싱하기
파이썬 크롤링(Python Crawling)2018. 12. 8. 23:08
728x90
반응형
소스코드는 다음과 같습니다.
import urllib.request
from bs4 import BeautifulSoup
def main():
sourcecode = urllib.request.urlopen("https://news.sbs.co.kr/news/newsflash.do?plink=GNB&cooper=SBSNEWS").read()
soup = BeautifulSoup(sourcecode, "html.parser")
list_href = []
list_content = []
for href in soup.find_all("div", class_="mfn_inner"):
list_href.append("https://news.sbs.co.kr" + href.find("a")["href"])
for i in range(0, len(list_href)):
url = list_href[i]
sourcecode = urllib.request.urlopen(url).read()
soup = BeautifulSoup(sourcecode, "html.parser")
list_content.append(soup.find("div", class_="text_area").get_text())
print(list_href)
print(list_content)
if __name__ == "__main__":
main()
728x90
반응형
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) 정규식과 엑셀 활용하기 (0) | 2018.12.09 |
---|---|
파이썬(Python) 네이트 판 최신 뉴스 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 스포츠 동아 최신 뉴스 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이트 판 댓글 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이버 영화 리뷰 파싱하기 (0) | 2018.12.08 |