Code:
from bs4 import BeautifulSoup
from urllib.parse import unquote
import re
import requests
html_url = '<http://www.5278.mobi/>??????.html' #html_url ,please replace it
def get_video(html_url):
r = requests.get(html_url).text
r = BeautifulSoup(r, 'html.parser')
iframe_url = r.iframe['src']
r = requests.get(iframe_url).text
pattern = r'\\brand\\b.\\d*&'
r = re.sub(pattern, '', r)
pattern = r'\\bget3.php\\b.id=\\w*'
api_url = '<https://v.5278.mobi/api/>' + re.search(pattern, r).group(0)
headers = {
'Host': 'v.5278.mobi',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'Accept': '*/*',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5',
'Accept-Language': 'zh-cn',
'Referer': iframe_url,
'DNT': '1'
}
r = requests.get(api_url, headers=headers).text
html_unescape = unquote(r)
video_url = BeautifulSoup(html_unescape, 'html.parser').source['src']
pattern = r'\\\\'
video_url = eval(re.sub(pattern, '', video_url))
return video_url
We can get direct video link in this way
Notice⚠️
There are two kinds of direct link, one is in m3u8 (vast majority), the other is mp4
The direct link of mp4 format cannot download or open directly, so we need set a header
Referer : api_url