【问题标题】:Python YouTube Gdata API broken after small changePython YouTube Gdata API 在小改动后损坏
【发布时间】:2011-12-07 20:46:43
【问题描述】:

我更改了脚本获取列表的方式,但不知何故我破坏了 Gdata-API

sys.argv[1]a text file of urls like this

当我注释掉第 1 部分和第 2 部分并添加 3 时,错误开始。当我删除 3 并取消注释第 1 部分和第 2 部分时,它再次起作用。

相关代码:

# PART 1 - parse bookmarks.html
#with open(sys.argv[1]) as bookmark_file:
#    soup = BeautifulSoup(bookmark_file.read())

# PART 2 - extract youtube video urls
#video_url_regex = re.compile('http://www.youtube.com/watch')
#urls = [link['href'] for link in soup('a', href=video_url_regex)]

# PART 3 - parse text file
urls = open(sys.argv[1]).readlines()

我现在得到的错误:

Traceback (most recent call last):
  File "listtest.py", line 81, in <module>
    comments = comments.total_results.text
AttributeError: 'NoneType' object has no attribute 'total_results'

我想继续获取“总评论数”字段。谢谢。

完整代码: http://pastebin.com/1yZdEySW

编辑:文本文件中的一个 URL 很好。当文本文件增加到两个或更多项时,就会重现错误。

【问题讨论】:

    标签: python youtube youtube-api


    【解决方案1】:

    我指定的网址是:

    urls = ['http://www.youtube.com/watch?v=_wmD3M-BfVo']
    

    (是的,这是 T-Pain 音乐视频) 它工作得很好。您打开的文件或对该文件内容的解析很可能有问题。或者你只是没有正确解析它。无论如何,由于您没有传入有效的 id,因此您将 cmets 分配给 none。

    【讨论】:

    • 当列表只有一项时效果很好。当它增加到两个或更多时,我得到了错误。
    • comments.total_results.text 更改为entry.comments.feed_link[0].count_hint 修复了它。仍然不确定为什么。
    猜你喜欢
    • 2011-11-12
    • 2013-04-10
    • 2015-03-24
    • 2012-05-06
    • 2011-02-21
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多