[問題] 如何爬url會變的video
https://sme.ivs.hinet.net/public/hls_player?page=cpc&did=2021040821
上面是要爬的影像,f12找到m3u8的網址,但是動態的一陣子就變了
附上我寫的程式,目前只能不斷由f12找到影片網址,有沒有什麼方法可以找到動態網址
import m3u8
# 原始的網址
https://sme.ivs.hinet.net/public/hls_player?page=cpc&did=2021040821
# f12看到的影片m3u8網址
baseurl='https://relay-203-69-5-85.vrs.hinet.net/live/cam2021040821/8b6a268e31c54a0eb73de76295bd4a7f/NORMAL/'
import requests
def write_ts(baseurl,tsname):
with open(tsname, 'wb') as f:
ts = get_ts(baseurl+tsname)
f.write(ts)
def get_ts(url):
try:
response = requests.get(url, verify=False)
response.raise_for_status()
response.encoding = 'utf-8'
return response.content
except Exception as err:
print(err)
return b''
import time
for i in range(144):
playlist = m3u8.load(baseurl+'/index.m3u8')
write_ts(baseurl,playlist.segments[0].uri )
print(playlist.segments[0].uri)
time.sleep(30) # Sleep for 30 second
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.140.207 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1644907546.A.F6D.html
推
02/15 15:29,
2年前
, 1F
02/15 15:29, 1F
→
02/15 15:29,
2年前
, 2F
02/15 15:29, 2F
→
02/16 15:56,
2年前
, 3F
02/16 15:56, 3F
→
02/17 00:23,
2年前
, 4F
02/17 00:23, 4F
推
02/18 04:32,
2年前
, 5F
02/18 04:32, 5F