Getting comments from YouTube via Python’s

Posted on

I would like to download comments from YouTube. This is possible via the Python module. python-gdata is a Debian/Ubuntu module of GData but may not include the most recent additions, such as the youtube module, so it may be necessary to download the gdata-python-client package with something like:

tar vfxz gdata-2.0.2.tar.gz
cd gdata-2.0.2
python install --home=~/python

With some help provided by the python code of Giles Bowkett it is now possible to download some of the comments to a video on YouTube with the following lines of Python code:

yts =
urlpattern = '' +
index = 1
url = urlpattern % index
comments = []
while url:
  ytfeed = yts.GetYouTubeVideoCommentFeed(uri=url)
  comments.extend([ comment.content.text for comment in ytfeed.entry ])
  url = ytfeed.GetNextLink().href
  print url

It seems only to be possible to download 1000 comments, – see also Stephen Mesa’s comment. So the small script will error after 1000 comments have been downloaded…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s