강의

멘토링

커뮤니티

Inflearn Community Q&A

gomsi12081477's profile image
gomsi12081477

asked

[New Revised Edition] This is Real Web Crawling - Basic Edition

Practical Crawling Step 1: How to Crawl a Single Product

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

Written on

·

321

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)

Answer 2

1

sk a님의 프로필 이미지
sk a
Questioner

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

0

startcoding님의 프로필 이미지
startcoding
Instructor

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

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

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

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

gomsi12081477's profile image
gomsi12081477

asked

Ask a question