使用python下载嵌入式视频

使用python下载嵌入式视频,python,video,web-scraping,Python,Video,Web Scraping,我试图通过python下载一个emmbedded链接,下面是一个示例链接 当我导航到该页面时,需要加载一些内容,还必须按play键 任何帮助都将不胜感激。如果您查看生成的页面源代码(加载DOM并运行javascript代码后),您将看到它是一个HTML页面(而不是视频链接)。源代码包含生成此html的javascript代码: <div id="playerContainer_videoContainer_container" role="main" style="position: r

我试图通过python下载一个emmbedded链接,下面是一个示例链接

当我导航到该页面时,需要加载一些内容,还必须按play键


任何帮助都将不胜感激。

如果您查看生成的页面源代码(加载DOM并运行javascript代码后),您将看到它是一个HTML页面(而不是视频链接)。源代码包含生成此html的javascript代码:

<div id="playerContainer_videoContainer_container" role="main" style="position: relative; display: block; margin-left: auto; margin-right: auto; width: 1902px; height: 1070px; top: 0px;">
<div id="overlayContainer" role="main" style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; overflow: hidden; z-index: 10;"></div>
<img id="playerContainer_videoContainer_bkg" src="config/profiles/resources/slide_professor_paella.jpg" alt="" width="100%" height="100%" style="position: relative; top: 0px; left: 0px; right: 0px; bottom: 0px; z-index: 0;">
<video id="playerContainer_videoContainer_1" preload="auto" style="top: 18.4722%; left: 0.390625%; width: 65%; height: 65%; position: absolute; z-index: 1;" poster="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/attachment-5/presenter_delivery.jpg">
    <source src="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/24320288-b79e-49e5-93b6-96b4c208f8cb/presenter_delivery.mp4" type="video/mp4">
</video>
<video id="playerContainer_videoContainer_2" preload="auto" style="top: 33.4722%; left: 66.0156%; width: 33.75%; height: 33.75%; position: absolute; z-index: 1;" poster="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/attachment-8/presentation_delivery.jpg">
    <source src="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/93271e20-3f4b-4650-a7e3-95aac41fd3e5/presentation_delivery.mp4" type="video/mp4">
</video>
如果您检查
网络
选项卡(在开发者工具栏中),您将注意到对该url的ajax请求:

https://matterhorn.dce.harvard.edu/search/episode.json?id=f7ff1893-fbf7-4909-b44e-12e61a98a677&_=1477764682940
(您可以看到这里的
id
与原始URL中的id相同)

此请求的响应是一个json字符串:

{"search-results":{"searchTime":"1","total":"1","limit":"1","offset":"0","query":"(id:f7ff1893\\-fbf7\\-4909\\-b44e\\-12e61a98a677) AND oc_organization:mh_default_org AND (o
只是部分回应,因为它太大了,不能放在这里

部分回应是:

search-results.result.mediapackage.media.track
其中有6个项目,每个项目都有一个URL属性,可用于获取相关视频链接:


我认为这些信息为您提供了一个很好的起点:)

如果您查看生成的页面源代码(在加载DOM并运行javascript代码之后),您将看到它是一个HTML页面(而不是指向视频的链接)。源代码包含生成此html的javascript代码:

<div id="playerContainer_videoContainer_container" role="main" style="position: relative; display: block; margin-left: auto; margin-right: auto; width: 1902px; height: 1070px; top: 0px;">
<div id="overlayContainer" role="main" style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; overflow: hidden; z-index: 10;"></div>
<img id="playerContainer_videoContainer_bkg" src="config/profiles/resources/slide_professor_paella.jpg" alt="" width="100%" height="100%" style="position: relative; top: 0px; left: 0px; right: 0px; bottom: 0px; z-index: 0;">
<video id="playerContainer_videoContainer_1" preload="auto" style="top: 18.4722%; left: 0.390625%; width: 65%; height: 65%; position: absolute; z-index: 1;" poster="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/attachment-5/presenter_delivery.jpg">
    <source src="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/24320288-b79e-49e5-93b6-96b4c208f8cb/presenter_delivery.mp4" type="video/mp4">
</video>
<video id="playerContainer_videoContainer_2" preload="auto" style="top: 33.4722%; left: 66.0156%; width: 33.75%; height: 33.75%; position: absolute; z-index: 1;" poster="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/attachment-8/presentation_delivery.jpg">
    <source src="https://da4w749qm6awt.cloudfront.net/engage-player/f7ff1893-fbf7-4909-b44e-12e61a98a677/93271e20-3f4b-4650-a7e3-95aac41fd3e5/presentation_delivery.mp4" type="video/mp4">
</video>
如果您检查
网络
选项卡(在开发者工具栏中),您将注意到对该url的ajax请求:

https://matterhorn.dce.harvard.edu/search/episode.json?id=f7ff1893-fbf7-4909-b44e-12e61a98a677&_=1477764682940
(您可以看到这里的
id
与原始URL中的id相同)

此请求的响应是一个json字符串:

{"search-results":{"searchTime":"1","total":"1","limit":"1","offset":"0","query":"(id:f7ff1893\\-fbf7\\-4909\\-b44e\\-12e61a98a677) AND oc_organization:mh_default_org AND (o
只是部分回应,因为它太大了,不能放在这里

部分回应是:

search-results.result.mediapackage.media.track
其中有6个项目,每个项目都有一个URL属性,可用于获取相关视频链接:


我认为这些信息为您提供了一个很好的起点:)

非常棒的解释,我在想我们是否可以使用第一个javascript输出获取源代码,然后使用Python转到该源代码并阅读?是否可以告诉我您使用了哪些代码来提取我发布的链接的html,我正在尝试使用requests.get()我的示例中的代码不是使用python提取的,而是使用浏览器提取的。正如我在回答中提到的,这是你的浏览器在加载DOM并运行javascript后生成的代码。哦,我知道,我有大约50个这样的链接,所以我想完成这项任务,因为我需要源代码,看起来,我应该手动检查源代码并下载videoNo,再读一遍我所有的答案。为了使这个过程自动化,您已经有了所有需要的东西。非常棒的解释,我在想我们可以使用第一个javascript输出来获取源代码,然后使用Python来访问该源代码并阅读吗?还可以告诉我您使用了哪些代码来提取我发布的链接的html,我正在尝试使用requests.get()我的示例中的代码不是使用python提取的,而是使用浏览器提取的。正如我在回答中提到的,这是你的浏览器在加载DOM并运行javascript后生成的代码。哦,我知道,我有大约50个这样的链接,所以我想完成这项任务,因为我需要源代码,看起来,我应该手动检查源代码并下载videoNo,再读一遍我所有的答案。你有所有你需要的东西来自动化这个过程。你检查我的答案了吗?如果您接受,我们将不胜感激。谢谢你核对我的答案了吗?如果您接受,我们将不胜感激。谢谢