작성
·
140
0
import requests
from bs4 import BeautifulSoup
response = requests.get('https://search.naver.com/search.naver?ssc=tab.news.all&where=news&sm=tab_jum&query=%EC%82%BC%EC%84%B1%EC%A0%84%EC%9E%90')
html = response.text
soup = BeautifulSoup(html, 'html.parser')
news_infos = soup.select(' div.info_group')
news_num = 1
for news_info in news_infos:
news_link = news_info.select('a.info')
if len(news_link) >= 2 :
url = news_link[1].attrs['href']
news_info = requests.get(url)
news = news_info.text
news_information = BeautifulSoup(news, 'html.parser')
news_text = news_information.select_one('article')
print(str(news_num) , "입니다>>>>>>>>>>>>>>>>")
print(news_text.text)
news_num += 1
CSS선택자를 article로 선택하고
출력을 하였더니 결과값 사이 사이에 줄바꿈이 있네요
없앨 수 있는 방법은 무엇일까요?
찾으셨군요 :)