• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    해결됨

네이버 일반 뉴스 페이지의 HTML이 변경된것 같습니다.

23.04.03 07:05 작성 23.04.03 07:08 수정 조회수 431

0

import requests
from bs4 import BeautifulSoup

response = requests.get(
    "https://search.naver.com/search.naver?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')
articles = soup.select("div.info_group")  # 뉴스 기사 div 10개 추출
for article in articles:
    links = article.select("a.info")  # 리스트
    if len(links) >= 2:  # 링크가 2개 이상이면
        url = links[1].attrs['href']  # 두번째 링크의 href를 추출
        response = requests.get(url, headers={'User-agent':'Mozila/5.0'})
        html = response.text
        soup = BeautifulSoup(html, 'html.parser')
        content = soup.select_one("#articleBodyContents")
        print(content.text)

본문 내용의 ID가 articleBodyContents아닙니다.

그래서 "#dic_area"로 생각해서,

변경하고 진행했는데, 강사님처럼 전체 텍스트가 출력되는게 아니라 일부만 출력됩니다.

전체 텍스트를 볼려면 어떻게 해야하나요?

답변 1

답변을 작성해보세요.

0

asd203n님의 프로필

asd203n

질문자

2023.04.03

해결됬습니다.