Python YouTube Gdata API 在小改动后就被破坏了

发布于 2024-12-20 13:43:16 字数 1042 浏览 0 评论 0原文

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

sys.argv[1] is 像这样的 url 文本文件

当我注释掉第 1 部分和第 1 部分时,错误就会开始。 2 并添加 3。当我删除 3 并取消注释第 1 部分和第 3 部分时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 就可以了。当文本文件增加到两个或更多项目时,会重现错误。

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

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

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.

Relevant code:

# 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()

Error I get now:

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.

Full Code:
http://pastebin.com/1yZdEySW

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独患者 2024-12-27 13:43:16

我指定的网址为:(

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

是的,这是 T-Pain 音乐视频)
而且效果很好。您很可能正在打开的文件或该文件内容的解析出现问题。或者你只是没有正确解析它。无论如何,您都会收到分配给 none 的评论,因为您没有传递有效的 id。

I assigned urls to be:

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

(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文