인프런 커뮤니티 질문&답변
뉴스 본문 링크 가져오기 오류
작성
·
324
1
import requests
from bs4 import BeautifulSoup
response = requests.get("https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=0&ie=utf8&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)
html = response.text
soup = BeautifulSoup(html, 'html.parser')
print(url)
강의보고 그대로 코드를 작성하였는데
아래와 같이 오류가 뜨네요
if (isinstance(value, str) or isinstance(value, collections.Callable) or hasattr(value, 'match')
^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Callable'






