小改动后 Python YouTube Gdata API 损坏 [英] Python YouTube Gdata API broken after small change

查看:23
本文介绍了小改动后 Python YouTube Gdata API 损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I changed how my script was getting it's list and somehow I broke the Gdata-API

sys.argv[1]这样的网址文本文件

当我注释掉第 1 部分 & 时,错误就开始了2 并添加 3.当我删除 3 并取消注释第 1 部分时2 又可以了.

The error starts when I comment out Part 1 & 2 and Add 3. When I Remove 3 and Uncomment Part 1 & 2 it works again.

相关代码:

# 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'

我想继续获取评论总数"字段.谢谢.

I'd like to continue getting the Total Comments field. Thanks.

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

文本文件中的一个 URL 就可以了.当文本文件增加到两个或更多项时,就会重现错误.

One URL in a text file is fine. When the text file is increased to two or more items then the error is reproduced.

推荐答案

我指定的网址为:

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

(是的,这是 T-Pain 音乐视频)它工作得很好.您很可能在打开的文件或解析该文件的内容时遇到问题.或者你只是没有正确解析它.在任何情况下,您都会收到未分配给任何评论的评论,因为您没有传入有效的 ID.

(Yeah, it's T-Pain music video) And it worked just fine. You most likely have a problem with the file you're opening or the parsing of the contents of that file. Or you just plain aren't parsing it right. In any event, you're getting comments assigned to none because you're not passing valid ids in.

这篇关于小改动后 Python YouTube Gdata API 损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆