Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.
黎赵太郎 edited this page Jul 15, 2016 · 2 revisions

声明

声明:以下所有API均由**知乎(Zhihu.INC)**提供,本人通过非正常手段获取。获取与共享的行为有侵犯知乎权益的嫌疑。若被告知停止使用与共享,本人将及时删除整个项目。请您知悉相关情况,遵守知乎的协议。API仅供学习交流使用,请勿用作商业用途。

说明

  • 知乎专栏的API均以json格式输出
  • http method均为GET

分析

1.获取专栏信息

https://zhuanlan.zhihu.com/api/columns/专栏名

如:

https://zhuanlan.zhihu.com/api/columns/wooyun

注意使用https,在旧版的API中使用的是http。

得到的信息:

{
    "followersCount": 31506,
    "description": "写点有用的东西。\nhttp://wooyun.org",
    "creator":
    {
        "bio": "请砍我的头。",
        "hash": "37841ec3e75e6583e627f64a21343b4d",
        "description": "",
        "profileUrl": "http://www.zhihu.com/people/____",
        "avatar":
        {
            "id": "6c83b4b34",
            "template": "http://pic1.zhimg.com/{id}_{size}.jpg"
        },
        "slug": "____",
        "name": "长短短"
    },
    "topics":
    [
        {
            "url": "http://www.zhihu.com/topic/19670074",
            "id": "19670074",
            "name": "乌云 (WooYun)"
        },
        {
            "url": "http://www.zhihu.com/topic/19554927",
            "id": "19554927",
            "name": "网络安全"
        }
    ],
    "href": "/api/columns/wooyun",
    "acceptSubmission": true,
    "slug": "wooyun",
    "name": "乌云君",
    "url": "/wooyun",
    "avatar":
    {
        "id": "0ec77eef1",
        "template": "https://pic2.zhimg.com/{id}_{size}.jpg"
    },
    "commentPermission": "anyone",
    "following": true,
    "postsCount": 50,
    "canPost": false,
    "activateAuthorRequested": false
}
followersCount:关注者数量
description:简介
creator:专栏所有者
avatar:头像
topics:话题

在获取头像地址时,将id拼接到template中即可获取到url,例如:

https://pic2.zhimg.com/424c70919_l.jpg
https://pic2.zhimg.com/424c70919_m.jpg
https://pic2.zhimg.com/424c70919_s.jpg

分别对应large,middle,small。 也可以不传入size参数,默认获取最大(large)。

2.获取某个专栏的文章列表

http://zhuanlan.zhihu.com/api/columns/专栏名/posts?limit=数量&offset=从哪里开始

如从wooyun获取前10条:

http://zhuanlan.zhihu.com/api/columns/wooyun/posts?limit=10&offset=0

limit为获取数量限制,测试超过10也是可以的,offset偏移量,从哪里开始获取。

得到的信息:

[
    {
        "rating": "like",
        "sourceUrl": "",
        "publishedTime": "2015-12-30T19:54:14+08:00",
        "links":
        {
            "comments": "http://zhuanlan.zhihu.com/api/columns/wooyun/posts/20460225/comments"
        },
        "author":
        {
            "bio": "信息安全,鸡尾酒,电吉他,摄影。",
            "hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
            "description": "写文字对于我来说挺痛苦的。",
            "profileUrl": "http://www.zhihu.com/people/fenggou",
            "avatar":
            {
                "id": "939c20127",
                "template": "http://pic4.zhimg.com/{id}_{size}.jpg"
            },
            "slug": "fenggou",
            "name": "fenggou"
        },
        "column":
        {
          "slug": "wooyun",
          "name": "乌云君"
        },
        "topics": [],
        "title": "用iPhone的,丢过或者要丢的赶紧进来瞅瞅(二)",
        "titleImage": "https://pic1.zhimg.com/aa0da1510a8d64c96bf811072a35addc_b.jpg",
        "summary": "简介省略",
        "content": "内容省略",
        "url": "/wooyun/20460225",
        "state": "published",
        "href": "/api/columns/wooyun/posts/20460225",
        "meta":
        {
          "previous": null,
          "next": null
        },
        "commentPermission": "anyone",
        "snapshotUrl": "",
        "canComment": true,
        "slug": 20460225,
        "commentsCount": 18,
        "likesCount": 152
    }
    ...
]

得到了一个json数组,需要注意的是titleImage的值可能为"".

3.获取特定文章

将已经得到的slug值进行拼接,即可获取特定文章信息。

https://zhuanlan.zhihu.com/api/posts/SLUG

如:

https://zhuanlan.zhihu.com/api/posts/20460225

得到的信息:

{
	"isTitleImageFullScreen": false,
	"rating": "none",
	"titleImage": "https://pic1.zhimg.com/aa0da1510a8d64c96bf811072a35addc_r.jpg",
	"links":
  {
    "comments": "/api/posts/20460225/comments"
  },
  "reviewers": [],
  "topics": [],
  "titleImageSize":
  {
    "width": 719,
    "height": 393
  },
  "href": "/api/posts/20460225",
  "author":
  {
    "bio": "bio",
    "hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
    "description": "description",
    "profileUrl": "https://www.zhihu.com/people/fenggou",
    "avatar":
    {
      "id": "939c20127",
      "template": "https://pic4.zhimg.com/{id}_{size}.jpg"
    },
    "slug": "fenggou",
    "name": "fenggou"
  },
  "content": "content",
  "state": "published",
  "sourceUrl": "",
  "canComment": true,
  "snapshotUrl": "",
  "slug": 20460225,
  "publishedTime": "2015-12-30T19:54:14+08:00",
  "url": "/p/20460225",
  "title": "title",
  "lastestLikers":
  [
  	{
  		"bio": "\u6c6a\u54c1\u4ea7",
  		"hash": "dfdcff7bf3fe6e6b47c3c85bd686cd82",
  		"description": "",
  		"profileUrl": "https://www.zhihu.com/people/li-lin-30-84",
  		"avatar":
  		{
  			"id": "f408bb13c37e131b3b461b5882a6f9d1",
  			"template": "https://pic2.zhimg.com/{id}_{size}.jpg"
  		},
  		"slug": "li-lin-30-84",
  		"name": "\u6797\u674e"
  	},
  	{
  		"bio": "\u6253\u6742",
  		"hash": "930502c3bb2cd807e2dc0ecf192f9867",
  		"description": "description",
  		"profileUrl": "https://www.zhihu.com/people/hu-xiao-yu-74-49",
  		"avatar":
  		{
  			"id": "87fd0f2a73313d5889e9a571bde43a8a",
  			"template": "https://pic3.zhimg.com/{id}_{size}.jpg"
  		},
  		"slug": "hu-xiao-yu-74-49",
  		"name": "\u80e1\u6653\u5b87"
  	},
  	...
  ],
  "summary": "summary",
  "column":
  {
  	"slug": "wooyun",
  	"name": "\u4e4c\u4e91\u541b"
  },
  "meta":
  {
  	"previous":
  	{
  		"isTitleImageFullScreen": false,
  		"rating": "none",
  		"titleImage": "https://pic3.zhimg.com/a30ea3ed0b85fb52baaae17f24691a12_r.jpg",
  		"links":
  		{
  			"comments": "/api/posts/20416511/comments"
  		},
  		"topics": [],
  		"href": "/api/posts/20416511",
  		"author":
  		{
  			"bio": "bio",
  			"hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
  			"description": "description",
  		  "profileUrl": "https://www.zhihu.com/people/fenggou",
  		  "avatar":
    		{
    			"id": "939c20127",
    			"template": "https://pic4.zhimg.com/{id}_{size}.jpg"
    		},
    		"slug": "fenggou",
    		"name": "fenggou"
  		},
  		"content": "content",
  		"state": "published",
  		"sourceUrl": "",
  		"canComment": true,
  		"snapshotUrl": "",
  		"slug": 20416511,
  		"publishedTime": "2015-12-14T19:13:38+08:00",
  		"url": "/p/20416511",
  		"title": "title",
  		"summary": "summary",
      "column":
      {
      	"slug": "wooyun",
      	"name": "\u4e4c\u4e91\u541b"
      },
      "meta":
      {
        "previous": null, "next": null
      },
      "commentPermission": "anyone",
      "commentsCount": 0,
      "likesCount": 0
  },
  "next":
  {
    "isTitleImageFullScreen": false,
    "rating": "none",
    "titleImage": "https://pic4.zhimg.com/04129f190219918c6f2c597daed1a6ab_r.jpg",
    "links":
    {
      "comments": "/api/posts/20581814/comments"
    },
    "topics": [],
    "href": "/api/posts/20581814",
    "author":
    {
      "bio": "bio",
      "hash": "1e373c5c6d9af3c8beaeb9aadc0890ac",
      "description": "description",
      "profileUrl": "https://www.zhihu.com/people/fenggou",
      "avatar":
      {
        "id": "939c20127",
        "template": "https://pic4.zhimg.com/{id}_{size}.jpg"
      },
      "slug": "fenggou",
      "name": "fenggou"
    },
    "content": "content",
    "state": "published",
    "sourceUrl": "",
    "canComment": true,
    "snapshotUrl": "",
    "slug": 20581814,
    "publishedTime": "2016-02-18T15:18:42+08:00",
    "url": "/p/20581814",
    "title": "title",
    "summary": "summary",
    "column":
    {
	  "slug": "wooyun",
	  "name": "\u4e4c\u4e91\u541b"
    },
    "meta":
    {
      "previous": null, "next": null
    },
    "commentPermission": "anyone",
    "commentsCount": 0,
    "likesCount": 0
    }
  },
  "commentPermission": "anyone",
  "commentsCount": 26,
  "likesCount": 240
}

通过示例数据可以看出:获取到的不仅仅是一篇文章,同时还获取到了上一篇和下一篇的值。

4.获取评论信息 获取到文章信息后,有一个字段comments,它所对应的值即为获取评论的地址

	"comments": "/api/posts/20460225/comments"

示例:

	https://zhuanlan.zhihu.com/api/posts/20460225/comments

获取到的json数组:

[
	{
		"liked": false, 
		"author": 
			{
				"bio": "Working in the dark to serve the light.", 
				"hash": "ab0f1a39723020f3ed9c1ba1f0948072", 
				"description": "", 
				"profileUrl": "https://www.zhihu.com/people/lan-diao-ye-qu",
				"avatar": 
					{
						"id": "dfb1995bdb6da62008d9a99741a3b96f", 
						"template": "https://pic4.zhimg.com/{id}_{size}.jpg"
					},
				"slug": "lan-diao-ye-qu",
				"name": "\u963f\u5361\u59c6\u9a91\u58eb"
			}, 
			"content": "content", 
			"href": "/api/posts/20460225/comments/111076966", 
			"createdTime": "2015-12-30T20:01:32+08:00", 
			"id": 111076966, 
			"likesCount": 0
	},
	...
]

通过这种方式获取,返回的array的size只有20.想要获取其他的评论方法和获取文章的方法一样,拼接url。

示例:

https://zhuanlan.zhihu.com/api/posts/20460225/comments?limit=30&offset=0

limit为要获取的数量,offset为偏移量。

Clone this wiki locally