프로그래밍/Python
[웹크롤링] 파이썬으로 삼성주식뉴스 가져오기
Leeys
2020. 9. 20. 02:56
반응형
In [1]:
import requests
from bs4 import BeautifulSoup
import pandas as pd
result = []
jour = []
for page in range(10):
raw = requests.get('https://search.naver.com/search.naver?&where=news&query=%EC%82%BC%EC%84%B1%EC%A0%84%EC%9E%90' + str(page * 10 + 1), headers={'User-Agent': 'Mozilla/5.0'}).text
html = BeautifulSoup(raw, 'html.parser')
articles = html.select('.type01 > li')
for article in articles:
journal = article.select_one('span._sp_each_source').text
title = article.select_one('a._sp_each_title').text
result.append(title)
jour.append(jour)
print('다음페이지')
In [ ]:
a = pd.DataFrame({'title' : title, 'journal' : jour})
print(len(a))
반응형