Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download this video using Selenium

I'm trying to make an python script to download videos from animefreak.tv so I can watch them offline while I'm on a roadtrip. Plus I thought it was a good opportunity to learn some webscraping.

I wrote this so far to download from this link http://animefreak.tv/watch/hacklegend-twilight-bracelet-episode-1-english-dubbed-online-free

URL = 'http://animefreak.tv/watch/one-piece-episode-1-english-dubbed-subbed'
IFRAME_POSITION = 2

# driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'])
driver = webdriver.Chrome()

driver.get(URL)
src = driver.page_source
parser = BeautifulSoup(src, 'lxml')


driver.switch_to.frame(IFRAME_POSITION)
video = driver.find_element(By.XPATH, '//*[@id="player"]/div[2]/video')


touch = webdriver.TouchActions(driver)
touch.tap(video)
print('src: ', video.get_property('src'))

driver.close()

Whenever I run the script the src attribute doesn't show up. What am I doing wrong? Thank you!

like image 463
Jeric Avatar asked Feb 11 '18 21:02

Jeric


People also ask

Can we upload/download file using selenium?

Uploading a File Using SeleniumIt's just a matter of sending the path of the file you want to upload to the text of the file-select input field. Then, you just have to click the Begin Upload button. By inspecting the elements on the page, you can find out that the button has the id js-file-input.

What is JDBC in selenium?

In selenium scripts, when there is a need of getting the Data from the database we may have to use APIs which helps to interact with database like JDBC. Java Database Connectivity(JDBC) is a Java API which is used to connect and interact with Database.


1 Answers

interesting that you are using both beautifulsoup and selenium. this task might be able to be accomplished using either one exclusively (with exceptions)

You won't use Selenium to download the video, per se. You'll use the language of choice. In your case, Python.

Python 2

import urllib
...
video_url = video.get_property('src')
urllib.urlretrieve(video_url, 'videoname.mp4')

Python 3

import urllib.request
...
video_url = video.get_property('src')
urllib.request.urlretrieve(video_url, 'videoname.mp4')

You'll probably have to calculate videoname.mp4 somehow so you don't get duplicates

like image 157
ddavison Avatar answered Oct 01 '22 03:10

ddavison