이 오류가 발생합니다. AttributeError : 'NoneType'object has no attribute 'append'함수를 만들었을 때 하나의 dict에 모든 항목 값을 저장하려고합니다.
rss_url = 'https://www.espn.com/espn/rss/' + league + '/news'
parser = feedparser.parse(rss_url)
newsInfo = {
'title': None,
'link': None,
'description': None,
'image': None
}
for entry in parser.entries:
newsInfo['title'].append(entry.title)
newsInfo['link'].append(entry.links[0].href)
newsInfo['description'].append(entry.description)
newsInfo['image'].append(entry.content[0].value)
return newsInfo
그러나 내가 사용하는 줄에서 .append
NoneType 오류가 발생합니다.
보너스 질문 : feedparser의 값을 HTML로 렌더링하면 뉴스가 올바르게 표시됩니까, 아니면 다른 단계가 있습니까?
목록으로 초기화 할 수 있습니다.
newsInfo = {
'title': [],
'link': [],
'description': [],
'image': []
}
또는 for 루프에 값을 할당하려는 경우 (사용 사례에 따라 다름) :
for entry in parser.entries:
newsInfo['title'] = entry.title
newsInfo['link'] = entry.links[0].href
newsInfo['description'] = entry.description
newsInfo['image'] = entry.content[0].value
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다