Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit effffdc

Browse files
Download video directly from youtube
1 parent a4b5465 commit effffdc

File tree

1 file changed

+42
-0
lines changed
  • Download Youtube Video from cmd using python

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from bs4 import BeautifulSoup
2+
import requests
3+
import urllib.request
4+
import json
5+
import time
6+
import selenium
7+
from selenium import webdriver
8+
from selenium.webdriver.common.keys import Keys
9+
10+
11+
url = input("Enter the Youtube-url\n")
12+
name = input("Enter the name for the video\n")
13+
name=name+".mp4"
14+
try:
15+
16+
# Phantom JS
17+
18+
driver = webdriver.PhantomJS(executable_path=r'C:\Users\ankit\Downloads\phantomjs-2.1.1-windows (1)\phantomjs-2.1.1-windows\bin\phantomjs.exe')
19+
driver.set_window_size(1120, 550)
20+
driver.get("http://en.savefrom.net")
21+
22+
# FireFox
23+
24+
# driver = webdriver.Firefox()
25+
# driver.get("http://en.savefrom.net")
26+
27+
shURL = driver.find_element_by_xpath('//input[@id="sf_url" and @type="text"]')
28+
shURL.send_keys(url)
29+
time.sleep(2)
30+
shSubmit = driver.find_element_by_xpath('//button[@id="sf_submit" and @class="submit" and @name="sf_submit"]')
31+
shSubmit.click()
32+
time.sleep(10)
33+
soup = BeautifulSoup(driver.page_source, 'html.parser')
34+
click = soup.find("a", class_="link link-download subname ga_track_events download-icon")
35+
url_parse = click.get("href")
36+
driver.quit()
37+
print("Downloading Starts..\n")
38+
# print(url_parse)
39+
urllib.request.urlretrieve(url_parse, name)
40+
print("Download Completed..!!!")
41+
except Exception as e:
42+
print(e)

0 commit comments

Comments
 (0)