Python错误-'函数'对象不可迭代

时间:2019-06-26 22:22:01

标签: python parsing beautifulsoup swift2 urllib2

我正在尝试使用以下代码从网站中解析一些数据,错误如下:

File "/home/osmc/.kodi/.../addon.py", line 81, in latest_episode
items = 
thisiscriminal.compile_latest_episode(compile_latest)
File "/home/osmc/.kodi/.../thisiscriminal.py", line 217, in compile_latest_episode
for podcast in get_latest_episode:
TypeError: 'function' object is not iterable
-->End of Python script error report<--

该函数不可迭代到底是什么意思? 217行是:

    for podcast in get_latest_episode:

这是它所引用的两位代码-任何指针将不胜感激:

def compile_latest_episode(compile_latest):
"""
@para: list containing dict of key/values pairs for playable podcasts
"""
items = []

for podcast in get_latest_episode:
    items.append({
            'label': podcast['title'],
#            'thumbnail': podcast['thumbnail'],
            'path': podcast['url'],
#            'info': podcast['desc'],
            'is_playable': True,
})

return items

并且:

def get_latest_episode(soup):
"""
@param: parsed html page            
"""
subjects = []

for content in soup.find_all('section'):

    try:        
        link = content.find('p')
        link = link.get('href')
        print "\n\nLink: ", link

#       title = content.find('h4','h3')
        title = content.find('h4')
        title = title.get_text()

#       desc = content.find('article')
#       desc = desc.get_text()

#       thumbnail = content.find('img')
#       thumbnail = thumbnail.get('srcset')

    except AttributeError:
        continue

    item = {
            'url': link,
            'title': title,
#            'desc': desc,
#            'thumbnail': thumbnail
    }

    subjects.append(item) 

return subjects

0 个答案:

没有答案