From 47d36939846ada8aaaccbe63331a173b2d5db72e Mon Sep 17 00:00:00 2001 From: wbt5 Date: Sun, 3 Nov 2019 14:01:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=99=8E=E7=89=99=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_hy_real_url.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/get_hy_real_url.py b/get_hy_real_url.py index 32eeadb..93f4c5f 100644 --- a/get_hy_real_url.py +++ b/get_hy_real_url.py @@ -1,9 +1,12 @@ +# 获取虎牙直播的真实流媒体地址。 + + import requests import re def get_real_url(rid): - room_url = 'https://m.huya.com/' + rid + room_url = 'https://m.huya.com/' + str(rid) header = { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36' @@ -11,10 +14,13 @@ def get_real_url(rid): response = requests.get(url=room_url, headers=header) pattern = r"hasvedio: '([\s\S]*.m3u8)" result = re.findall(pattern, response.text, re.I) - real_url = result[0] + if result: + real_url = result[0] + else: + real_url = '未开播或直播间不存在' return real_url rid = input('请输入虎牙房间号:\n') real_url = get_real_url(rid) -print('该直播间地址为:\n' + real_url) +print('该直播间源地址为:\n' + real_url)