• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

뉴스의 제목이 하나 만 출력됩니다

23.09.21 14:40 작성 조회수 150

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')
links = soup.select('.news_tit')

for link in links:
    title = link.text
    url = link.attrs['href']
print(title,url)

답변 2

·

답변을 작성해보세요.

1

sk a님의 프로필

sk a

질문자

2023.09.23

가르쳐 주신대로 하니 해결되었습니다 감사합니다

0

for link in links:
    title = link.text
    url = link.attrs['href']
    print(title,url)

이런식으로 마지막 코드를 들여쓰기 해주셔야 합니다 :)

for 명령어의 동작방식을 아래 영상으로 다시 한번 학습해 보세요 ㅎㅎ

https://youtu.be/j58o7UU2kNs?list=PLNO7MWpu0eeVfqT9ehXWf9CdRALusjUsU