我想从reddit处理一些json:https://www.reddit.com/r/videos/top.json?limit=3
{
"kind": "Listing",
"data": {
"modhash": "",
"children": [
{
"kind": "t3",
"data": {
"contest_mode": false,
"banned_by": null,
"domain": "youtube.com",
"subreddit": "videos",
"selftext_html": null,
"selftext": "",
"likes": null,
"suggested_sort": null,
"user_reports": [],
"secure_media": {
"oembed": {
"provider_url": "https://www.youtube.com/",
"version": "1.0",
"title": "SpaceX Interplanetary Transport System",
"thumbnail_width": 480,
"height": 338,
"width": 600,
"html": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/0qo78R_yYFA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"author_name": "SpaceX",
"thumbnail_height": 360,
"thumbnail_url": "https://i.ytimg.com/vi/0qo78R_yYFA/hqdefault.jpg",
"type": "video",
"provider_name": "YouTube",
"author_url": "https://www.youtube.com/user/spacexchannel"
},
"type": "youtube.com"
},
"saved": false,
"id": "54rrjl",
"gilded": 0,
"secure_media_embed": {
"content": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/0qo78R_yYFA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"width": 600,
"scrolling": false,
"height": 338
},
"clicked": false,
"report_reasons": null,
"author": "jclishman",
"media": {
"oembed": {
"provider_url": "https://www.youtube.com/",
"version": "1.0",
"title": "SpaceX Interplanetary Transport System",
"thumbnail_width": 480,
"height": 338,
"width": 600,
"html": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/0qo78R_yYFA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"author_name": "SpaceX",
"thumbnail_height": 360,
"thumbnail_url": "https://i.ytimg.com/vi/0qo78R_yYFA/hqdefault.jpg",
"type": "video",
"provider_name": "YouTube",
"author_url": "https://www.youtube.com/user/spacexchannel"
},
"type": "youtube.com"
},
"name": "t3_54rrjl",
"score": 4947,
"approved_by": null,
"over_18": false,
"removal_reason": null,
"hidden": false,
"preview": {
"images": [
{
"source": {
"url": "https://i.redditmedia.com/UmxPKXyvkXx8ap0ugxIgFu2yB00xZPrnR80zTb-kRlc.jpg?s=bdeffae704dbca1cf477f09608479cd9",
"width": 480,
"height": 360
},
"resolutions": [
{
"url": "https://i.redditmedia.com/UmxPKXyvkXx8ap0ugxIgFu2yB00xZPrnR80zTb-kRlc.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=108&s=45a9e73c27ba9d344b75793ac6951567",
"width": 108,
"height": 81
},
{
"url": "https://i.redditmedia.com/UmxPKXyvkXx8ap0ugxIgFu2yB00xZPrnR80zTb-kRlc.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=216&s=a59e97b76b1347e2f26333ec2c7d50c1",
"width": 216,
"height": 162
},
{
"url": "https://i.redditmedia.com/UmxPKXyvkXx8ap0ugxIgFu2yB00xZPrnR80zTb-kRlc.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=320&s=631ddd2156d83ee7fec1c6f4c98c5c4b",
"width": 320,
"height": 240
}
],
"variants": {},
"id": "0sz_ShT1IlShzb117hpblwELVvmEgpD3n_WCpw94VN4"
}
]
},
"thumbnail": "http://b.thumbs.redditmedia.com/TLG2iK4WvyVntpjBcKPIyRinq2zKEvOuK8z0klQhmvY.jpg",
"subreddit_id": "t5_2qh1e",
"edited": false,
"link_flair_css_class": null,
"author_flair_css_class": null,
"downs": 0,
"mod_reports": [],
"archived": false,
"media_embed": {
"content": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/0qo78R_yYFA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"width": 600,
"scrolling": false,
"height": 338
},
"post_hint": "rich:video",
"is_self": false,
"hide_score": false,
"permalink": "/r/videos/comments/54rrjl/spacex_interplanetary_transport_system/",
"locked": false,
"stickied": false,
"created": 1475026717,
"url": "https://www.youtube.com/watch?v=0qo78R_yYFA",
"author_flair_text": null,
"quarantine": false,
"title": "SpaceX Interplanetary Transport System",
"created_utc": 1474997917,
"link_flair_text": null,
"distinguished": null,
"num_comments": 1077,
"visited": false,
"num_reports": null,
"ups": 4947
}
},
{
"kind": "t3",
"data": {
"contest_mode": false,
"banned_by": null,
"domain": "youtube.com",
"subreddit": "videos",
"selftext_html": null,
"selftext": "",
"likes": null,
"suggested_sort": null,
"user_reports": [],
"secure_media": {
"type": "youtube.com",
"oembed": {
"provider_url": "https://www.youtube.com/",
"title": "35 years Backwards thru Time with Sam Klemke (Time Lapse)",
"type": "video",
"html": "<iframe width=\"459\" height=\"344\" src=\"https://www.youtube.com/embed/K2xTBHyfOks?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"thumbnail_width": 480,
"height": 344,
"width": 459,
"version": "1.0",
"author_name": "MisterEsoteric",
"thumbnail_height": 360,
"thumbnail_url": "https://i.ytimg.com/vi/K2xTBHyfOks/hqdefault.jpg",
"provider_name": "YouTube",
"author_url": "https://www.youtube.com/user/MisterEsoteric"
}
},
"saved": false,
"id": "54r1gh",
"gilded": 0,
"secure_media_embed": {
"content": "<iframe width=\"459\" height=\"344\" src=\"https://www.youtube.com/embed/K2xTBHyfOks?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"width": 459,
"scrolling": false,
"height": 344
},
"clicked": false,
"report_reasons": null,
"author": "a_shootin_star",
"media": {
"type": "youtube.com",
"oembed": {
"provider_url": "https://www.youtube.com/",
"title": "35 years Backwards thru Time with Sam Klemke (Time Lapse)",
"type": "video",
"html": "<iframe width=\"459\" height=\"344\" src=\"https://www.youtube.com/embed/K2xTBHyfOks?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"thumbnail_width": 480,
"height": 344,
"width": 459,
"version": "1.0",
"author_name": "MisterEsoteric",
"thumbnail_height": 360,
"thumbnail_url": "https://i.ytimg.com/vi/K2xTBHyfOks/hqdefault.jpg",
"provider_name": "YouTube",
"author_url": "https://www.youtube.com/user/MisterEsoteric"
}
},
"name": "t3_54r1gh",
"score": 4631,
"approved_by": null,
"over_18": false,
"removal_reason": null,
"hidden": false,
"preview": {
"images": [
{
"source": {
"url": "https://i.redditmedia.com/ff7YtFDYgwsOuge92mnUE4rUT2fnJOctQJ6nJgMZoj8.jpg?s=21cd790f369febedcece048a2dc33714",
"width": 480,
"height": 360
},
"resolutions": [
{
"url": "https://i.redditmedia.com/ff7YtFDYgwsOuge92mnUE4rUT2fnJOctQJ6nJgMZoj8.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=108&s=42827db4a8eef7d90c8fd35339f134c8",
"width": 108,
"height": 81
},
{
"url": "https://i.redditmedia.com/ff7YtFDYgwsOuge92mnUE4rUT2fnJOctQJ6nJgMZoj8.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=216&s=a33acbee6c5ea92382fa5c7c0f76979c",
"width": 216,
"height": 162
},
{
"url": "https://i.redditmedia.com/ff7YtFDYgwsOuge92mnUE4rUT2fnJOctQJ6nJgMZoj8.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=320&s=c7c2a52e55089b17da7fc0d35c57b484",
"width": 320,
"height": 240
}
],
"variants": {},
"id": "fLOkvXgiEKsZnefFoNcOTKy0x6dk9ODi6cLVi9MMHGo"
}
]
},
"thumbnail": "http://b.thumbs.redditmedia.com/RZUqE22jXxl1xbkqptl99WMkyLwYxXOjTSgd-Uy7nAE.jpg",
"subreddit_id": "t5_2qh1e",
"edited": false,
"link_flair_css_class": null,
"author_flair_css_class": null,
"downs": 0,
"mod_reports": [],
"archived": false,
"media_embed": {
"content": "<iframe width=\"459\" height=\"344\" src=\"https://www.youtube.com/embed/K2xTBHyfOks?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"width": 459,
"scrolling": false,
"height": 344
},
"post_hint": "rich:video",
"is_self": false,
"hide_score": false,
"permalink": "/r/videos/comments/54r1gh/there_is_a_man_who_filmed_himself_annually_for_35/",
"locked": false,
"stickied": false,
"created": 1475018163,
"url": "https://www.youtube.com/watch?v=K2xTBHyfOks",
"author_flair_text": null,
"quarantine": false,
"title": "There is a man who filmed himself annually for 35 years and made a video going backwards to 1977. [ORIGINAL] - [06:31]",
"created_utc": 1474989363,
"link_flair_text": null,
"distinguished": null,
"num_comments": 1345,
"visited": false,
"num_reports": null,
"ups": 4631
}
},
{
"kind": "t3",
"data": {
"contest_mode": false,
"banned_by": null,
"domain": "youtube.com",
"subreddit": "videos",
"selftext_html": null,
"selftext": "",
"likes": null,
"suggested_sort": null,
"user_reports": [],
"secure_media": {
"type": "youtube.com",
"oembed": {
"provider_url": "https://www.youtube.com/",
"version": "1.0",
"title": "How Patton Oswalt & His Daughter Are Coping With His Wife's Passing - CONAN on TBS",
"author_name": "Team Coco",
"height": 338,
"width": 600,
"html": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/iuLKSvoK8KA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"thumbnail_width": 480,
"thumbnail_height": 360,
"thumbnail_url": "https://i.ytimg.com/vi/iuLKSvoK8KA/hqdefault.jpg",
"type": "video",
"provider_name": "YouTube",
"author_url": "https://www.youtube.com/user/teamcoco"
}
},
"saved": false,
"id": "54s0sm",
"gilded": 0,
"secure_media_embed": {
"content": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/iuLKSvoK8KA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"width": 600,
"scrolling": false,
"height": 338
},
"clicked": false,
"report_reasons": null,
"author": "bruhfamsquad",
"media": {
"type": "youtube.com",
"oembed": {
"provider_url": "https://www.youtube.com/",
"version": "1.0",
"title": "How Patton Oswalt & His Daughter Are Coping With His Wife's Passing - CONAN on TBS",
"author_name": "Team Coco",
"height": 338,
"width": 600,
"html": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/iuLKSvoK8KA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"thumbnail_width": 480,
"thumbnail_height": 360,
"thumbnail_url": "https://i.ytimg.com/vi/iuLKSvoK8KA/hqdefault.jpg",
"type": "video",
"provider_name": "YouTube",
"author_url": "https://www.youtube.com/user/teamcoco"
}
},
"name": "t3_54s0sm",
"score": 3732,
"approved_by": null,
"over_18": false,
"removal_reason": null,
"hidden": false,
"preview": {
"images": [
{
"source": {
"url": "https://i.redditmedia.com/mY4uWOaN90_K5IMcDhz_FtmLtZFyGQZYiMNeSljv9xs.jpg?s=e0fa03c1cfbec29d8d4a2745fea0094c",
"width": 480,
"height": 360
},
"resolutions": [
{
"url": "https://i.redditmedia.com/mY4uWOaN90_K5IMcDhz_FtmLtZFyGQZYiMNeSljv9xs.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=108&s=c51d04dbef9f3121ec0955d6f7be6cbd",
"width": 108,
"height": 81
},
{
"url": "https://i.redditmedia.com/mY4uWOaN90_K5IMcDhz_FtmLtZFyGQZYiMNeSljv9xs.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=216&s=f0e15bfd6bc17745be698e670de399f9",
"width": 216,
"height": 162
},
{
"url": "https://i.redditmedia.com/mY4uWOaN90_K5IMcDhz_FtmLtZFyGQZYiMNeSljv9xs.jpg?fit=crop&crop=faces%2Centropy&arh=2&w=320&s=648cdbd8af77fa7b6542a038e6f8fc86",
"width": 320,
"height": 240
}
],
"variants": {},
"id": "JAjE3xovazbxxz0FI8I3lwu2TWLLRVxOg6hPeoDPrWI"
}
]
},
"thumbnail": "http://b.thumbs.redditmedia.com/R89XcpIkm4e6NqHhiNzE6JmPU6kxVibipzbesVYg6oY.jpg",
"subreddit_id": "t5_2qh1e",
"edited": false,
"link_flair_css_class": null,
"author_flair_css_class": null,
"downs": 0,
"mod_reports": [],
"archived": false,
"media_embed": {
"content": "<iframe width=\"600\" height=\"338\" src=\"https://www.youtube.com/embed/iuLKSvoK8KA?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>",
"width": 600,
"scrolling": false,
"height": 338
},
"post_hint": "rich:video",
"is_self": false,
"hide_score": false,
"permalink": "/r/videos/comments/54s0sm/how_patton_oswalt_his_daughter_are_coping_with/",
"locked": false,
"stickied": false,
"created": 1475029674,
"url": "https://www.youtube.com/watch?v=iuLKSvoK8KA",
"author_flair_text": null,
"quarantine": false,
"title": "How Patton Oswalt & His Daughter Are Coping With His Wife's Passing",
"created_utc": 1475000874,
"link_flair_text": null,
"distinguished": null,
"num_comments": 565,
"visited": false,
"num_reports": null,
"ups": 3732
}
}
],
"after": "t3_54s0sm",
"before": null
}
}
$ curl https://www.reddit.com/r/videos/top.json\?limit\=3 | \
jq -r '(.data.children|.[].data.title),(.data.children|.[].data.url),(.data.children|.[].data.score)'
它产生以下输出:
SpaceX Interplanetary Transport System
There is a man who filmed himself annually for 35 years and made a video going backwards to 1977. [ORIGINAL] - [06:31]
Japanese men trying to pronounce "Massachusetts"
https://www.youtube.com/watch?v=0qo78R_yYFA
https://www.youtube.com/watch?v=K2xTBHyfOks
https://www.youtube.com/watch?v=69iSXks1bes
4874
4644
5075
我想获得以下输出:
SpaceX Interplanetary Transport System, https://www.youtube.com/watch?v=0qo78R_yYFA, 4874
There is a man who filmed himself annually for 35 years and made a video going backwards to 1977. [ORIGINAL] - [06:31], https://www.youtube.com/watch?v=K2xTBHyfOks, 4644
Japanese men trying to pronounce "Massachusetts", https://www.youtube.com/watch?v=69iSXks1bes, 5075
如何调整返回结果的方式?
答案 0 :(得分:1)
您感兴趣的字段位于每个data
的{{1}}个对象中。您希望将它们保持在一起,因此您应该限制您浏览子项目的次数,只需执行一次。而且您似乎正在以CSV格式输出,因此您可以使用children
。首先将属性放在数组中。
@csv