강의

멘토링

커뮤니티

Inflearn コミュニティ Q&A

junujin のプロフィール画像
junujin

投稿した質問数

[新規改訂版] これが本当のクローリングだ - 実践編 (人工知能収益化)

選択から除外する

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

解決済みの質問

作成

·

574

·

編集済み

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"로 생각해서,

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

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

python웹-크롤링

回答 1

0

asd203n님의 프로필 이미지
asd203n
質問者

해결됬습니다.

junujin のプロフィール画像
junujin

投稿した質問数

質問する