
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
네이버 뉴스기사 -> '삼성전자' 키워드로 검색 내용중
기사 타이틀을 마우스 우클릭 후 검사 버튼을 누르고
<a> 링크의 셀렉터를 copy 하기 했을때 나오는 셀렉터는
#sp_nws1 > div.news_wrap.api_ani_send > div > div.news_contents > a.news_tit
입니다. 그리고 해당 셀렉터를 이용하여 soup.select_one()함수에 셀렉터를 넣어 실행하면
None이라는 결과가 나옵니다.

soup를 print하여 naver.html로 저장하고 브라우저로 띄워 봤더니 검색서비스 이용이 제한되었습니다. 라는 문구가 나옵니다.

작성한 코드 및 에러 메세지
네이버 뉴스기사의 특정 타이틀을 가져와야 하지만
None을 응답함
네이버 api를 활용해 보았습니다.
import os
import sys
import urllib.request
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
encText = urllib.parse.quote("검색할 단어")
url = "https://openapi.naver.com/v1/search/blog?query=" + encText # JSON 결과
# url = "https://openapi.naver.com/v1/search/blog.xml?query=" + encText # XML 결과
request = urllib.request.Request(url)
request.add_header("X-Naver-Client-Id",client_id)
request.add_header("X-Naver-Client-Secret",client_secret)
response = urllib.request.urlopen(request)
rescode = response.getcode()
if(rescode==200):
content = response.read()
print(response_body.decode('utf-8'))
else:
print("Error Code:" + rescode)
import json
content = json.loads(content)
items = content.get('items', [])
for item in items :
title = item.get("title", "")
link = item.get("link", "")
description = item.get("description", "")
bloggername = item.get("bloggername", "")
bloggerlink = item.get("bloggerlink", "")
postdate = item.get("postdate", "")
# 원하는 작업 수행
print("Title:", title)
print("Link:", link)
#print("Description:", description)
#print("Blogger Name:", bloggername)
#print("Blogger Link:", bloggerlink)
#print("Post Date:", postdate)
#print()
get_news("현대자동차")
get_news("LG전자")
encText 에 검색하고자하는 키워드를 넣고
함수화하면
똑같이 작동합니다.

