短视频解析源码

123456   ·   发表于 27天前   ·   源码分享

<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:15.0pt;">import requests
import json
import logging
import re
from urllib import parse


def analysis_douying(share_url):
    try:
        response = requests.get(share_url, allow_redirects=False)
        aweme_id = re.findall('(\d+)', parse.urlparse(response.headers.get('Location')).path)[0]
    except Exception as e:
        logging.warning('错误的地址 {}'.format(e))
        return json.dumps({'status': 0, 'info': '错误的地址'})
    url = 'https://aweme.snssdk.com/aweme/v1/aweme/detail/'
    params = {
        "aweme_id": aweme_id,
        "origin_type": "web",
        "retry_type": "no_retry",
        "iid": "75186358813",
        "device_id": "68273753722",
        "ac": "wifi",
        "channel": "tengxun_new",
        "aid": "1128",
        "app_name": "aweme",
        "version_code": "660",
        "version_name": "6.6.0",
        "device_platform": "android",
        "ssmix": "a",
        "device_type": "OPPO R11",
        "device_brand": "OPPO ",
        "language": "zh",
        "os_api": "22",
        "os_version": "5.1.1",
        "uuid": "866174010180467",
        "openudid": "b42e992398373803",
        "manifest_version_code": "660",
        "resolution": "720*1280",
        "dpi": "240",
        "update_version_code": "6602",
        "_rticket": "1560432451284",
        "mcc_mnc": "46007",
        "js_sdk_version": "1.16.2.7",
        "ts": "1560432451"
    }
    headers = {
        'User-Agent': 'com.ss.android.ugc.aweme/660 (Linux; U; Android 5.1.1; zh_CN; OPPO R11; Build/NMF26X; Cronet/58.0.2991.0)'
    }
    response = requests.get(url=url, params=params, headers=headers)
    json_info = json.loads(response.text)
    try:
        title = json_info['aweme_detail']['desc']
        rel_video_url = json_info['aweme_detail']['video']['play_addr']['url_list'][0]
        return json.dumps({'status': 1, 'title': title, 'rel_video_url': rel_video_url})
    except Exception as e:
        logging.warning('解析失败: {}'.format(e))
        return json.dumps({'status': 0, 'info': '解析失败'})


if __name__ == '__main__':
    print(json.loads(analysis_douying('http://v.douyin.com/rqW8M5/')))

</pre>

短视频
0 Reply   |  Until 27天前 | 199 View
LoginCan Publish Content