'How to download a video when I get the URL of the MP4 file in selenium python? (WITHOUT URLLIB)

I can get to the point where the video is right in front of me. I need to loop through the urls and download all of these videos. The issue is that the request is stateful and I cannot use urllib because then authorization issues occur. How do I just target the three dots in chrome video viewer and download the file?

All I need now is to be able to download by clicking on the download button. I do not know if it can be done without the specification of coordinates. Like I said, the urls follow a pattern and I can generate them. The only issue is the authorization. Please help me get the videos through selenium.

Note that the video is in JavaScript so I cannot really target the three dots or the download button.



Solution 1:[1]

You can get the cookies from the driver and pass the information to the Request session. So, you can download with the Requests library.

import requests

cookies = driver.get_cookies()
s = requests.Session()
for cookie in cookies:
    s.cookies.set(cookie['name'], cookie['value'])
response = s.get(urlDownload, stream=True)
print(response.status_code)
with open(fileName,'wb') as f:
    f.write(response.content)

Solution 2:[2]

you can use selenium in python 2 as you have only pics i cannot give you a real code but something like that will help.you can find XPath by inspecting HTML

    import selenium 
    driver.find_element_by_xpath('xpath of 3 dots')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vinicius Folha
Solution 2 Zeeshan Ahmad