如何使用Selenium下载此视频

如何使用Selenium下载此视频

本文介绍了如何使用Selenium下载此视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图制作一个python脚本来从animefreak.tv下载视频,以便在旅途中可以离线观看它们.另外,我认为这是学习网络抓捕的好机会.

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.

到目前为止,我已经编写了此文件,可以从此链接下载 http://animefreak.tv/watch/hacklegend-twilight-bracelet-episode-1-english-dubbed-online-free

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()

每当我运行脚本时,src属性都不会显示.我究竟做错了什么?谢谢!

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

推荐答案

有趣的是,您同时使用beautifulsoup和硒.可以仅使用其中一个(例外)完成该任务

您本身不会使用Selenium下载视频.您将使用选择的语言.就您而言,是Python.

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

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')

您可能必须以某种方式计算videoname.mp4,以免出现重复

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

这篇关于如何使用Selenium下载此视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:39