파이썬(Python) JTBC 뉴스 기사 파싱하여 날짜별로 통계 구하기
소스코드는 다음과 같습니다.
import urllib.request from bs4 import BeautifulSoup import matplotlib.pyplot as plt def main(): url = "http://news.jtbc.joins.com/section/index.aspx?scode=70" sourcecode = urllib.request.urlopen(url).read() soup = BeautifulSoup(sourcecode, "html.parser") times = [] for i in range(0, 20): times.append(soup.find_all("span", class_="date")[i].get_text().strip()) edited = [] for i in range(0, len(times)): edited.append(times[i][8:10]) count1 = 0 count2 = 0 count3 = 0 count4 = 0 for i in range(0, len(edited)): if edited[i] == "05": # 05일 기사 개수 구하기 count1 = count1 + 1 elif edited[i] == "06": # 06일 기사 개수 구하기 count2 = count2 + 1 elif edited[i] == "07": # 07일 기사 개수 구하기 count3 = count3 + 1 elif edited[i] == "08": # 08일 기사 개수 구하기 count4 = count4 + 1 days = [count1, count2, count3, count4] activities = ['05', '06', '07', '08'] colors = ['red', 'blue', 'green', 'yellow'] plt.pie(days, labels=activities, colors=colors, startangle=90, autopct='%.2f%%') plt.show() if __name__ == "__main__": main()
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) 정규식과 엑셀 활용하기 (0) | 2018.12.09 |
---|---|
파이썬(Python) 네이트 판 최신 뉴스 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) SBS 최신 뉴스 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 스포츠 동아 최신 뉴스 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이트 판 댓글 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이트 판 최신 뉴스 기사 파싱하기
소스코드는 다음과 같습니다.
import urllib.request
from bs4 import BeautifulSoup
def main():
url = "https://news.nate.com/recent?mid=n0100"
sourcecode = urllib.request.urlopen(url).read()
soup = BeautifulSoup(sourcecode, "html.parser")
divs = soup.find_all("div", class_="mduSubjectList")
for div in divs :
link = div.find("a")["href"]
print("http:" + link)
if __name__ == "__main__":
main()
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) JTBC 뉴스 기사 파싱하여 날짜별로 통계 구하기 (4) | 2018.12.09 |
---|---|
파이썬(Python) 정규식과 엑셀 활용하기 (0) | 2018.12.09 |
파이썬(Python) SBS 최신 뉴스 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 스포츠 동아 최신 뉴스 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이트 판 댓글 파싱하기 (0) | 2018.12.08 |
파이썬(Python) SBS 최신 뉴스 파싱하기
소스코드는 다음과 같습니다.
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()
'파이썬 크롤링(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 |
파이썬(Python) 스포츠 동아 최신 뉴스 기사 파싱하기
소스코드는 다음과 같습니다.
import urllib.request
from bs4 import BeautifulSoup
def main():
for i in range(0, 10):
url = "http://sports.donga.com/Enter?p=" + str((i * 20) + 1) + "&c=02"
soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
spans = soup.find_all("span", class_="tit")
for j in range(0, 20):
print((i * 20) + j + 1, "번째 글:", spans[j + 3].get_text())
if __name__ == "__main__":
main()
또한 혹은 특정한 뉴스 기사 목록 페이지에서, 각 뉴스 기사 상세 페이지의 링크를 얻고 싶다면 다음과 같이 할 수 있습니다.
import urllib.request
from bs4 import BeautifulSoup
def main():
url = "http://sports.donga.com/Enter?p=1&c=02"
soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
spans = soup.find_all("span", class_="tit")
for i in range(0, 20):
print(spans[i + 3].find("a")["href"])
if __name__ == "__main__":
main()
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) 네이트 판 최신 뉴스 기사 파싱하기 (0) | 2018.12.08 |
---|---|
파이썬(Python) SBS 최신 뉴스 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이트 판 댓글 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이버 영화 리뷰 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 클리앙 게시판 파싱하기 (1) | 2018.12.08 |
파이썬(Python) 네이트 판 댓글 파싱하기
소스코드는 다음과 같습니다.
import urllib.request
from bs4 import BeautifulSoup
def main():
url = "https://pann.nate.com/talk/344403021"
soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser")
comments = []
for i in soup.find_all("dd", class_="usertxt"):
comments.append(i.get_text().strip("\n\t "))
print(comments)
if __name__ == "__main__":
main()
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) SBS 최신 뉴스 파싱하기 (0) | 2018.12.08 |
---|---|
파이썬(Python) 스포츠 동아 최신 뉴스 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이버 영화 리뷰 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 클리앙 게시판 파싱하기 (1) | 2018.12.08 |
파이썬(Python) 경기일보 최신 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 클리앙 게시판 파싱하기
소스코드는 다음과 같습니다.
import urllib.request
from bs4 import BeautifulSoup
def main():
soup = BeautifulSoup(urllib.request.urlopen("https://www.clien.net/service/group/community").read(), "html.parser")
list_title = []
list_nickname = []
for i in soup.find_all("span", class_="subject_fixed"):
list_title.append(i.get_text())
for i in soup.find_all("span", class_="nickname"):
list_nickname.append(i.get_text())
print(list_title)
print(list_nickname)
if __name__ == "__main__":
main()
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) 네이트 판 댓글 파싱하기 (0) | 2018.12.08 |
---|---|
파이썬(Python) 네이버 영화 리뷰 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 경기일보 최신 기사 파싱하기 (0) | 2018.12.08 |
파이썬(Python) 네이버 인기 검색어 파싱하기 (0) | 2018.12.08 |
셀레니움(Selenium)을 활용해 네이버 자동 로그인 및 메일 정보 가져오기 (2) | 2018.08.20 |
파이썬(Python) 경기일보 최신 기사 파싱하기
소스코드는 다음과 같습니다.
import urllib.request from bs4 import BeautifulSoup def main(): url = "http://www.kyeonggi.com/news/articleList.html?sc_section_code=S1N2&view_type=sm" soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html.parser") list_title = [] list_content = []
# 기사 제목 파싱 for news_title in soup.find_all("div", class_="list-titles"): list_title.append(news_title.get_text())
# 기사 요약 파싱 for news_content in soup.find_all("p", class_="list-summary"): list_content.append(news_content.get_text()) print(list_title) print(list_content) if __name__ == "__main__": main()
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) 네이버 영화 리뷰 파싱하기 (0) | 2018.12.08 |
---|---|
파이썬(Python) 클리앙 게시판 파싱하기 (1) | 2018.12.08 |
파이썬(Python) 네이버 인기 검색어 파싱하기 (0) | 2018.12.08 |
셀레니움(Selenium)을 활용해 네이버 자동 로그인 및 메일 정보 가져오기 (2) | 2018.08.20 |
웹 크롤러(Web Crawler)로 자동 로그인 및 주요 정보 추출하기 (0) | 2018.08.20 |
파이썬(Python) 네이버 인기 검색어 파싱하기
아래 소스코드를 이용하면 네이버 인기 검색어를 파싱할 수 있습니다. 왜냐하면 인기 검색어는 공통적으로 "ah_k"라는 클래스로 묶여 있기 때문입니다.
import urllib.request
from bs4 import BeautifulSoup
def main():
sourcecode = urllib.request.urlopen("http://www.naver.com").read()
soup = BeautifulSoup(sourcecode, "html.parser")
list = []
for naver_text in soup.find_all("span", class_="ah_k"):
list.append(naver_text.get_text())
print(list)
if __name__ == "__main__":
main()
'파이썬 크롤링(Python Crawling)' 카테고리의 다른 글
파이썬(Python) 클리앙 게시판 파싱하기 (1) | 2018.12.08 |
---|---|
파이썬(Python) 경기일보 최신 기사 파싱하기 (0) | 2018.12.08 |
셀레니움(Selenium)을 활용해 네이버 자동 로그인 및 메일 정보 가져오기 (2) | 2018.08.20 |
웹 크롤러(Web Crawler)로 자동 로그인 및 주요 정보 추출하기 (0) | 2018.08.20 |
웹 크롤러(Web Crawler)로 연속적인 크롤링하기 (1) | 2018.08.20 |