请注意,这个问题与我们如何下载blob url视频[关闭]不同,因为它不要求与浏览器进行人工交互。
我有以下问题:
我需要做的是:
注意,解决方案不需要与浏览器进行人工交互。就API而言,输入应该是URL列表,输出应该是视频/gifs列表。
如果要测试解决方案,可以找到示例页 这里。
我的理解是,我可以使用Selene获得HTML,并单击图像启动播放器。但是,我不知道如何处理blob以获得m3u8,然后将其用于实际的视频。
发布于 2021-03-18 04:08:57
稍微挖掘一下,你就不需要点击任何按钮了。单击按钮时,它将调用master.m3u8文件。使用dev工具,您可以将请求的url拼凑在一起。问题是,第一个文件不包含指向实际视频的链接。将另一个请求拼接在一起,以获得最终的m3u8文件。从那里,你可以使用其他的所以链接下载视频。它是分段的,所以下载起来并不简单。您可以取消对以下打印语句的注释,查看每个m3u8文件包含的内容。这也会在页面中循环。
import re
for i in range(6119, 6121):
url = 'https://www2.nhk.or.jp/signlanguage/sp/enquete.cgi?dno={}'.format(str(i))
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
print(soup.find(onclick=re.compile('signlanguage/movie'))) # locate the div that has the data we need
video_id = soup.find(onclick=re.compile('signlanguage/movie')).get('onclick').split(',')[1].replace("'","")
m3u8_url = 'https://nhks-vh.akamaihd.net/i/signlanguage/movie/v4/{}/{}.mp4/master.m3u8'.format(video_id[-1], video_id)
# this m3u8 file doesn't contain download links, the next one does; so download and save that one
r = requests.get(m3u8_url)
# print(r.text)
m3u8_url_2 = r.text.split('\n')[2] # get first link; high bandwidth
r2 = requests.get(m3u8_url_2)
# print(r2.text)
# there are other ways to download the file, i'm just creating a new one with the data read and writing to a file
fn = video_id + '.m3u8'
with open(fn, 'w+') as f:
f.write(r2.text)
f.close()https://stackoverflow.com/questions/66683933
复制相似问题