下载 imgur 图片 (jpg) 的热门评论

Downloading the top comments for an imgur image (jpg)

如何使用 json 访问与 imgur 图片相关的评论?

对于 http://imgur.com/gallery/DVNWyG8 , browsing to http://api.imgur.com/3/image/DVNWyG8.json 产量:

{"data":{"id":"DVNWyG8","title":"Fiber optic dress","description":null,"datetime":1476709283,"type":"image\/jpeg","animated":false,"width":2056,"height":1694,"size":482983,"views":1883274,"bandwidth":909589326342,"vote":null,"favorite":false,"nsfw":false,"section":"pics","account_url":null,"account_id":null,"is_ad":false,"in_gallery":true,"link":"http:\/\/i.imgur.com\/DVNWyG8.jpg"},"success":true,"status":200}

我也无法获取它,因为我收到此错误:

wget http://api.imgur.com/3/image/DVNWyG8.json
--2016-10-17 19:55:48--  http://api.imgur.com/3/image/DVNWyG8.json
Resolving api.imgur.com (api.imgur.com)... 151.101.44.193
Connecting to api.imgur.com (api.imgur.com)|151.101.44.193|:80... connected.
HTTP request sent, awaiting response... 400 Bad Request
2016-10-17 19:55:48 ERROR 400: Bad Request.

基本上我想下载一张包含前 30 条评论的 Imgur 图片。我想知道我是否应该用它的 json 做点什么,或者是否有一个整洁的 Python API 用于此目的?

即使使用 API,我也没有看到获取与图像相关的所有评论的方法:

  9 imgur_client = ImgurClient(client_id, client_secret, access_token, refresh_token)
 10 
 11 image = imgur_client.get_image("S1jmapR")
 12 print(image.title)
 13 print(image.link)
 14 print(dir(image))

我得到:

mona@pascal:~/computer_vision/imgur$ python download.py 
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Cat Ying & Yang
http://i.imgur.com/S1jmapR.jpg
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'account_id', 'account_url', 'animated', 'bandwidth', 'datetime', 'description', 'favorite', 'height', 'id', 'in_gallery', 'is_ad', 'link', 'nsfw', 'section', 'size', 'title', 'type', 'views', 'vote', 'width']
mona@pascal:~/computer_vision/imgur$ vi download.py

如您所见,图片没有评论方法或get_comment。

这里的 python 库可以满足您的需求,https://github.com/Imgur/imgurpython

 21 for item in imgur_client.gallery_item_comments("c1SN8", sort='best'):
 22     print item.comment

会做这份工作