Skip to content
Advertisement

With python’s selenium package, Why Chromedriver starts to display video instead of downloading when click on a tag?

  • Operating System: Windows 10, 64 bit
  • Editor: VSCode 1.55
  • Python: 3.9.0
    • selenium: 3.141.0

I want Chromedriver to start downloading the video when I click on a tag.

But instead, it opens a new tab and starts to display the video.

The site that I’m trying to download from: https://www.aparat.com/v/9y8M5?playlist=683341

enter image description here

enter image description here

enter image description here

here is my code if needed:

enter image description here

I will appreciate for any help.

Advertisement

Answer

Suppose, you just want to download the video, and don’t care about the way.

Actually, you have got the source url of the video, so you can download the video directely instead of clicking some element to show a Download Dialog.

A demo like this, replace b.pop().click() with it:

import requests

url = b.pop().get_attribute('href')
r = requests.get(url, allow_redirects=True)
open('video.mp4', 'wb').write(r.content)
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement