从 javascript 对象变量中提取 URL

从 javascript 对象变量中提取 URL

在网站中,我在<script>标签中包含了以下 javascript:

(function(e, t) {
    var a = {
        "cdn_url": "https://f.playerabc.com",
        "playerabc_api_url": "api.playerabc.com",
        "view": 1,
        "request": {
            "files": {
                "dash": {
                   ...
                    }],
                    "cdns": {
                      ...
                        }
                    },
                    "default_cdn": "akfire_interconnect_quic"
                },
                "hls": {
                   ...
                        }
                    }
                },
                "progressive": [{
                    "profile": 165,
                    "width": 960,
                    "mime": "video/mp4",
                    "fps": 24,
                    "url": "https://url1.com/893184125.mp4",
                    "cdn": "mai_connect",
                    "quality": "540p",
                    "id": 893184125,
                    "origin": "gcs",
                    "height": 540
                }, {
                    "profile": 164,
                    "width": 640,
                    "mime": "video/mp4",
                    "fps": 24,
                    "url": "https://url2.com/893184120.mp4",
                    "cdn": "mai_connect",
                    "quality": "360p",
                    "id": 893184120,
                    "origin": "gcs",
                    "height": 360
                }, {
                    "profile": 174,
                    "width": 1280,
                    "mime": "video/mp4",
                    "fps": 24,
                    "url": "https://url3.com/893184095.mp4", 
                    "cdn": "mai_connect",
                    "quality": "720p",
                    "id": 893184095,
                    "origin": "gcs",
                    "height": 720
                }]
            },
           ...
    };

我想提取具有 720p 视频的 URL 链接(https://url3.com/893184095.mp4

我该怎么做呢?

答案1

如果您确定这是对象结构,则可以通过点符号访问 URL:

var url = a.request.files.progressive[1].url;

这会将“url”分配给您在示例中提供的 url。如果您想使用“progressive”对象提取其他内容,请将 [] 内的数字更改为 0 或 2

相关内容