一、前言
从现在开始会偶尔写一些付费的内容,之所以要写付费内容,主要基于以下几点,占比权重依次降低。
1、我喜欢钱。
2、建立有用知识的门槛,把有用的东西给予真正需要的人。
3、通过付费倒逼我写出更好的文章,如果文章不好你可以尽情吐槽,前提是你花了钱。
二、抖音介绍
抖音现在真的是越来越火,我们公司的“一面APP”也想做对抖音APP的数据抓取。基于此,我下载抖音,开始研究它的HTTP请求内容,后来我发现它有毒,越刷越上瘾,总感觉下一个视频一定会更精彩,根本停不下来,似乎早已忘记当初为什么下载抖音...
当然,最后我还是控制着了。
三、获取抖音中某个“挑战”下热门视频及单个视频的URL
关于对APP进行抓包的方法,在这我不做讲解,这个方法在网上可以找到很多相关资料(收费价值不大)。
如果我们要获取抖音中某个“挑战”下热门视频,大概的步骤如下:
1)配置好Fiddler或Charles(我这边是使用Charles),通过Charles可以对手机APP进行抓包,如下图1所示;
2)在抖音APP上进行挑战的内容搜索,例如搜索“绝地求生”,如下图2所示;
3)点击“绝地求生”挑战,查看Charles中的HTTP请求数据,找出获取挑战下视频的API,如下图3所示;
我们发现在我们点击“绝地求生”进入这个挑战的详情页面时,抖音APP向服务端申请了两个接口请求。
一个是detail,它里面包含的是这个挑战的一些具体信息,因为我需要的是视频信息,所以这个我们先不管。
另一个是aweme,它的接口内容如下:
https://aweme.snssdk.com/aweme/v1/challenge/aweme/?iid=30373511894&device_id=35781128184&os_api=18&app_name=aweme&channel=App%20Store&idfa=811A8841-030F-4AEA-B934-C2A56489C32D&device_platform=iphone&build_number=17805&vid=A4BB3AF4-7981-4805-995B-78419881DC11&openudid=99bf2b608173e21cefd562496d2cf21fa8eba580&device_type=iPhone7,2&app_version=1.7.8&version_code=1.7.8&os_version=11.3&screen_width=750&aid=1128&ac=WIFI&ch_id=1574030716416014&count=21&cursor=0&pull_type=2&query_type=0&type=5&mas=001469ed4a7a3f61de046e21c8c7ae8bcb64a983471da18ec0c8d1&as=a1c5206d9e676a38ee4960&ts=1524500606
同时通过查看这个接口返回的JSON数据,也确定这个是获取视频的API,如下是返回的JSON视频数据(只保留aweme_list中的第一条数据,用于分析):
{
"has_more" : 1,
"cursor" : 21,
"rid" : "201804240023290100100511301210FF",
"status_code" : 0,
"extra" : {
"logid" : "201804240023290100100511301210FF",
"now" : 1524500609305,
"fatal_item_ids" : []
},
"aweme_list" : [
{
"text_extra" : [],
"status" : {
"is_delete" : false,
"allow_share" : true,
"is_private" : false,
"allow_comment" : true,
"private_status" : 0,
"with_goods" : false
},
"author_user_id" : 60978405851,
"is_hash_tag" : 0,
"create_time" : 1501112821,
"aweme_type" : 0,
"cha_list" : [
{
"schema" : "aweme:\/\/aweme\/challenge\/detail?cid=1574030716416014",
"user_count" : 0,
"author" : {},
"cha_name" : "绝地求生",
"type" : 0,
"desc" : "吃鸡吃鸡!今晚吃鸡!",
"cid" : "1574030716416014"
}
],
"region" : "CN",
"user_digged" : 0,
"share_info" : {
"share_weibo_desc" : "#在抖音,记录美好生活#空气泳",
"share_title" : "空气泳",
"share_url" : "https:\/\/www.iesdouyin.com\/share\/video\/6447230455191178509\/?region=CN&mid=6443685673772944141&titleType=title",
"share_desc" : "在抖音,记录美好生活"
},
"video" : {
"dynamic_cover" : {
"url_list" : [
"https:\/\/p3.pstatp.com\/obj\/30b20017abc8da2a1379",
"https:\/\/pb9.pstatp.com\/obj\/30b20017abc8da2a1379",
"https:\/\/pb3.pstatp.com\/obj\/30b20017abc8da2a1379"
],
"uri" : "30b20017abc8da2a1379"
},
"play_addr_lowbr" : {
"url_list" : [
"https:\/\/aweme.snssdk.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=0&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/api.amemv.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=0&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/aweme.snssdk.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=1&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/api.amemv.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=1&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0"
],
"uri" : "fe29c6e0c74a40f6baf22400552d6d2f"
},
"width" : 540,
"ratio" : "720p",
"play_addr" : {
"url_list" : [
"https:\/\/aweme.snssdk.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=0&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/api.amemv.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=0&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/aweme.snssdk.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=1&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/api.amemv.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=1&ratio=720p&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0"
],
"uri" : "fe29c6e0c74a40f6baf22400552d6d2f"
},
"cover" : {
"url_list" : [
"https:\/\/p1.pstatp.com\/aweme\/300x400\/30b600031f0eca5498aa.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/300x400\/30b600031f0eca5498aa.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/300x400\/30b600031f0eca5498aa.jpeg"
],
"uri" : "300x400\/30b600031f0eca5498aa"
},
"height" : 960,
"bit_rate" : [
{
"bit_rate" : 4325045,
"gear_name" : "normal",
"quality_type" : 0
}
],
"origin_cover" : {
"url_list" : [
"http:\/\/p1.pstatp.com\/large\/30b600031f0eca5498aa.jpeg",
"http:\/\/pb3.pstatp.com\/large\/30b600031f0eca5498aa.jpeg",
"http:\/\/pb3.pstatp.com\/large\/30b600031f0eca5498aa.jpeg"
],
"uri" : "large\/30b600031f0eca5498aa"
},
"duration" : 3820,
"download_addr" : {
"url_list" : [
"https:\/\/aweme.snssdk.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=0&ratio=720p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/api.amemv.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=0&ratio=720p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/aweme.snssdk.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=1&ratio=720p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0",
"https:\/\/api.amemv.com\/aweme\/v1\/play\/?video_id=fe29c6e0c74a40f6baf22400552d6d2f&line=1&ratio=720p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0"
],
"uri" : "fe29c6e0c74a40f6baf22400552d6d2f"
},
"has_watermark" : true
},
"is_vr" : false,
"vr_type" : 0,
"share_url" : "https:\/\/www.douyin.com\/share\/video\/6447230455191178509\/?mid=6443685673772944141",
"sort_label" : "",
"music" : {
"cover_hd" : {
"url_list" : [
"http:\/\/p3.pstatp.com\/live\/1080x1080\/2bd9005342019b56cf7e.jpeg"
],
"uri" : "2bd9005342019b56cf7e"
},
"cover_large" : {
"url_list" : [
"http:\/\/p3.pstatp.com\/live\/720x720\/2bd9005342019b56cf7e.jpeg"
],
"uri" : "2bd9005342019b56cf7e"
},
"status" : 1,
"extra" : "{\"has_edited\": 0}",
"user_count" : 0,
"title" : "Iceland",
"duration" : 32,
"play_url" : {
"url_list" : [
"http:\/\/p1.pstatp.com\/obj\/29c70000654ea97a6169",
"http:\/\/p9.pstatp.com\/obj\/29c70000654ea97a6169",
"http:\/\/p3.pstatp.com\/obj\/29c70000654ea97a6169"
],
"uri" : "29c70000654ea97a6169"
},
"mid" : "6443685673772944141",
"offline_desc" : "",
"schema_url" : "",
"cover_medium" : {
"url_list" : [
"http:\/\/p3.pstatp.com\/live\/200x200\/2bd9005342019b56cf7e.jpeg"
],
"uri" : "2bd9005342019b56cf7e"
},
"is_original" : false,
"id" : 6443685673772944141,
"cover_thumb" : {
"url_list" : [
"http:\/\/p3.pstatp.com\/live\/100x100\/2bd9005342019b56cf7e.jpeg"
],
"uri" : "2bd9005342019b56cf7e"
},
"audio_track" : {
"url_list" : [
"https:\/\/p1.pstatp.com\/obj\/46bd000dbd65c3dfd8ba",
"https:\/\/pb3.pstatp.com\/obj\/46bd000dbd65c3dfd8ba",
"https:\/\/pb3.pstatp.com\/obj\/46bd000dbd65c3dfd8ba"
],
"uri" : "46bd000dbd65c3dfd8ba"
},
"effects_data" : {
"url_list" : [
"https:\/\/p1.pstatp.com\/obj\/2efe00235ebf732bb56f",
"https:\/\/pb3.pstatp.com\/obj\/2efe00235ebf732bb56f",
"https:\/\/pb3.pstatp.com\/obj\/2efe00235ebf732bb56f"
],
"uri" : "2efe00235ebf732bb56f"
},
"source_platform" : 22,
"author" : "FlyBoy,Gavrielle",
"id_str" : "6443685673772944141"
},
"is_top" : 0,
"aweme_id" : "6447230455191178509",
"cmt_swt" : false,
"risk_infos" : {
"warn" : false,
"content" : "",
"risk_sink" : false,
"type" : 0
},
"label_origin_author" : {
"url_list" : [
"https:\/\/p3.pstatp.com\/obj\/216a001ff805affc1dab",
"https:\/\/pb9.pstatp.com\/obj\/216a001ff805affc1dab",
"https:\/\/pb3.pstatp.com\/obj\/216a001ff805affc1dab"
],
"uri" : "216a001ff805affc1dab"
},
"label_origin_author_text" : "发起者",
"label_top" : {
"url_list" : [
"https:\/\/p3.pstatp.com\/obj\/c150000f34767e2cb56",
"https:\/\/pb9.pstatp.com\/obj\/c150000f34767e2cb56",
"https:\/\/pb3.pstatp.com\/obj\/c150000f34767e2cb56"
],
"uri" : "c150000f34767e2cb56"
},
"is_ads" : false,
"statistics" : {
"digg_count" : 19578,
"aweme_id" : "6447230455191178509",
"share_count" : 283,
"play_count" : 1296122,
"comment_count" : 100
},
"video_labels" : [],
"rate" : 12,
"bodydance_score" : 0,
"desc" : "空气泳",
"author" : {
"special_lock" : 0,
"is_binded_weibo" : false,
"shield_follow_notice" : 0,
"nickname_lock" : 0,
"avatar_larger" : {
"url_list" : [
"https:\/\/p1.pstatp.com\/aweme\/1080x1080\/38c90028f622dd195aaf.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/1080x1080\/38c90028f622dd195aaf.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/1080x1080\/38c90028f622dd195aaf.jpeg"
],
"uri" : "38c90028f622dd195aaf"
},
"follow_status" : 0,
"with_commerce_entry" : false,
"original_music_qrcode" : null,
"authority_status" : 0,
"is_ad_fake" : false,
"prevent_download" : false,
"enterprise_verify" : false,
"verification_type" : 1,
"app_id" : 1128,
"weibo_url" : "",
"community_discipline_status" : 0,
"risk_flag" : 0,
"need_recommend" : 1,
"live_rec_level" : 0,
"unique_id" : "MysticzZ",
"hide_location" : false,
"enterprise_verify_reason" : "",
"short_id" : "17612748",
"account_region" : "",
"star_use_new_download" : false,
"signature" : "颓",
"avatar_medium" : {
"url_list" : [
"https:\/\/p1.pstatp.com\/aweme\/720x720\/38c90028f622dd195aaf.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/720x720\/38c90028f622dd195aaf.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/720x720\/38c90028f622dd195aaf.jpeg"
],
"uri" : "38c90028f622dd195aaf"
},
"verify_info" : "",
"create_time" : 1495648525,
"story_open" : false,
"region" : "CN",
"hide_search" : false,
"avatar_thumb" : {
"url_list" : [
"https:\/\/p1.pstatp.com\/aweme\/100x100\/38c90028f622dd195aaf.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/100x100\/38c90028f622dd195aaf.jpeg",
"https:\/\/pb3.pstatp.com\/aweme\/100x100\/38c90028f622dd195aaf.jpeg"
],
"uri" : "38c90028f622dd195aaf"
},
"school_poi_id" : "",
"update_before" : 0,
"shield_comment_notice" : 0,
"original_music_cover" : null,
"shield_digg_notice" : 0,
"bind_phone" : "",
"live_verify" : 0,
"birthday" : "1999-03-28",
"school_type" : 0,
"uid" : "60978405851",
"avatar_uri" : "38c90028f622dd195aaf",
"weibo_schema" : "",
"is_verified" : true,
"custom_verify" : "",
"commerce_user_level" : 0,
"gender" : 1,
"has_register_notice" : 0,
"reflow_page_gid" : 0,
"reflow_page_uid" : 0,
"nickname" : "Atlantis.",
"weibo_verify" : "",
"language" : "zh-Hans",
"share_qrcode_uri" : "216a0035fc39c9e9376f",
"room_id" : 0,
"constellation" : 1,
"school_name" : "",
"weibo_name" : ""
},
"is_relieve" : false
},
{
...第二条数据
}
...其他更多的数据
]
}
4)对这个API进行分析(破解或者绕过API的加密),找出可以直接获取JSON数据的纯种API;
API的内容为:
https://aweme.snssdk.com/aweme/v1/challenge/aweme/?iid=30373511894&device_id=35781128184&os_api=18&app_name=aweme&channel=App%20Store&idfa=811A8841-030F-4AEA-B934-C2A56489C32D&device_platform=iphone&build_number=17805&vid=A4BB3AF4-7981-4805-995B-78419881DC11&openudid=99bf2b608173e21cefd562496d2cf21fa8eba580&device_type=iPhone7,2&app_version=1.7.8&version_code=1.7.8&os_version=11.3&screen_width=750&aid=1128&ac=WIFI&ch_id=1574030716416014&count=21&cursor=0&pull_type=2&query_type=0&type=5&mas=001469ed4a7a3f61de046e21c8c7ae8bcb64a983471da18ec0c8d1&as=a1c5206d9e676a38ee4960&ts=1524500606
。
为了便于分析,我们先把一些无关的手机设备和版本信息除掉: https://aweme.snssdk.com/aweme/v1/challenge/aweme/?ch_id=1574030716416014&count=21&cursor=0&pull_type=2&query_type=0&type=5&as=a1c5206d9e676a38ee4960&ts=1524500606
它现在只剩下ch_id、count、cursor、pull_type、query_type、type、as以及ts几个参数,其中pull_type、query_type和type三个是固定的,不用管。cursor和count是获取的数据的开始和数量,ch_id应该是挑战的唯一标示。接下来就是as和ts两个参数,通过多次实验,我们发现这个API使用了as和cp参数进行了加密处理,也就是说我们无法使用这个API直接获取到API的数据,需要对as、ts的加密算法进行破解。当然,上面我也提过,面对这个情况,要么破解算法要么绕过加密,原则上是能够绕过的就不要选择破解,因为破解的难度很大,需要逆向,这个以后再讲(我也没做过)。
APP或PC上破解不了的接口,可以尝试使用m站。这个是我们的一贯原则。
我们发现抖音中的挑战有一个分享按钮,我们试着分享出这个H5页面来进行分析,分享之后的URL为:
https://www.iesdouyin.com/share/challenge/1574030716416014?utm_campaign=client_share&app=aweme&utm_medium=ios&iid=30373511894&utm_source=weixin&tt_from=weixin&utm_source=weixin&utm_medium=aweme_ios&utm_campaign=client_share&uid=58875748483&did=30373511894
在浏览器上打开这个URL,通过分析它的请求,只看XHR,见下图4: