Python YouTube Gdata API 在小改动后就被破坏了
我改变了脚本获取列表的方式,不知何故我破坏了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我指定的网址为:(
是的,这是 T-Pain 音乐视频)
而且效果很好。您很可能正在打开的文件或该文件内容的解析出现问题。或者你只是没有正确解析它。无论如何,您都会收到分配给 none 的评论,因为您没有传递有效的 id。
I assigned urls to be:
(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.