0

On Chrome, when I hit Inspect > Network I see the .mp4 file I want.

Here is a screenshot. Screenshot

When I double click the .mp4 file, it opens a separate page where the video starts playing.

How exactly do I download this video using Selenium?

The HTML for the second page:


<html>
   <head>
      <meta name="viewport" content="width=device-width">
      <input type="hidden" id="_w_tusk">
      <script type="text/javascript" src="chrome-extension://dbjbempljhcmhlfpfacalomonjpalpko/scripts/inspector.js"></script>
      <script src="chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/prompt.js"></script>


<body class="vsc-initialized" style="">
   <div class="vsc-controller">
   </div><video controls="" autoplay="" name="media">
   <source src="https://download2.redactednetwork.com/597ef6c3a6d902ab173bc6ee77ba69d0/61c6d548/stream/V14728/V14728_vids/V14728_full_h264_1500.mp4" type="video/mp4">
   </video>
   <span id="copylAddress" style="display: inline-block; position: absolute; left: -9999em;"></span>
   </body>

Screenshot of second pageenter image description here

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
zackchess3
  • 21
  • 3

1 Answers1

0

Selenium can only interact with the elements in the rendered webpage. It has no idea about the Network tab in the Developer tools. This means you have to look at the <source> tag from the page and then parse the src attribute. You can then download the file at that URL. How to download any file and save it to the desired location using Selenium Webdriver explains how to do it with selenium. Or you can use a HTTP library such as requests.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Thank you for the help. I still don't know how to do what I asked. – zackchess3 Dec 30 '21 at 06:21
  • @zackchess3 Which suggestions from my answer above have you tried to figure out? In case it isn't clear, the first step is to find a `` tag in the page then get the `src` attribute from that tag. Do you know how to do that? If not, I suggest digging more into the Selenium documentation. – Code-Apprentice Jan 01 '22 at 05:04
  • What exactly is the tag? Where is it located? – zackchess3 Jan 01 '22 at 22:54
  • @zackchess3 It's an HTML tag. I'm not familiar with it. I suggest you start by looking at the screenshot you posted. – Code-Apprentice Jan 04 '22 at 16:16