인프런 커뮤니티 질문&답변
도무지 안 되네요..ㅠㅠ
작성
·
234
1
import requests
from bs4 import BeautifulSoup
import pyautogui
import pyautogui as pg
header = {'User-agent': 'Mozilla/2.0'}
seoData = pyautogui.prompt('검색어를 입력해라')
response = requests.get(f"https://search.naver.com/search.naver?where=news&sm=tab_jum&query= {seoData}", headers=header)
html = response.text
soup = BeautifulSoup(html, 'html.parser')
articles = soup.select("div.info_group") #뉴스 기사 div 10개 추출
#print(articles[0].attrs('href'))
for article in articles:
links = article.select("a.info") #리스트
if len(links) >= 2: #링크가 2개 이상이면
url = links[1].attrs('href') #두번째 링크의 href 추출
print(url)
코드를 이렇게 짰는데요.. 강의와 같이 한 것 같은데 실행하면
Traceback (most recent call last): File "c:\Users\movie\OneDrive\pythonStudy\startCoding\셀레니움\네이버연습\삼성전자네이버뉴스.py", line 19, in <module> url = links[1].attrs('href') #두번째 링크의 href 추출 TypeError: 'dict' object is not callable
이런 에러가 나오면서 url을 제대로 읽어오지 못합니다.
코드에 문제가 없는 것 같은데 해결 방법이 있을까요?ㅜㅜ






앗 댓글을 못보고
저도 계속 찾아보고 있었네요ㅋㅋㅋ
url = links[1].attrs('href') -> ['href']