javascript 使用python从vimeo下载嵌入式Iframe视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20534930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:44:03  来源:igfitidea点击:

Downloading embedded Iframe videos from vimeo using python

javascriptpythonvideodownloadvimeo

提问by Qndel

I have been looking all over and I see how to download vimeo videos using python. I so far have this code.I can get to the parent page but I cannot do anything to hit that iframe. I was thinking the best way to do this would be login and hit the iframe and download the video from there but I am missing something. do any of you have any ideas? let me know if you need more info and as always thank you for your time.

我一直在寻找,我看到了如何使用 python 下载 vimeo 视频。我到目前为止有这个代码。我可以进入父页面,但我无法做任何事情来点击 iframe。我在想最好的方法是登录并点击 iframe 并从那里下载视频,但我错过了一些东西。你们有什么想法吗?如果您需要更多信息,请告诉我,并一如既往地感谢您的抽出时间。

import spynner
import os, sys, urllib

os.system("dir")

browser = spynner.Browser()
#browser.show()
url = 'https://somelink.php'
browser.load("https://somelink2.php")
browser.wk_fill("input[name=log]", "loginname")
browser.wk_fill("input[name=pwd]", "password")
browser.click("#wp-submit")
print browser.url, len(browser.html)
browser.load("http://somelink3-00000333/")
browser.click("//player.vimeo.com/video/747474749")
print browser.html

Here is the embedded video that I would like to download.

这是我想下载的嵌入式视频。

<iframe src="//player.vimeo.com/video/747474749" width="500" height="281"
frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>

采纳答案by Qndel

The Site allowed for Javascript to be run from the client side. so in short a simply running javascript to access the link is enough. javascript:window.location.href="%s"; '%uls is really all that was needed to have this happen. I hope it helps others in the future and perhaps there is a better way to do this please let me know.

该站点允许从客户端运行 Javascript。所以简而言之,只需运行 javascript 来访问链接就足够了。javascript:window.location.href="%s"; '%uls 真的是让这一切发生所需要的。我希望它在未来对其他人有所帮助,也许有更好的方法可以做到这一点,请告诉我。

def getvideourl(htmldoc): 
        downloadurls = re.findall("//player.+video.\d+", htmldoc) 
        for uls in downloadurls: 
            uls.encode('ascii','ignore') 
            javasinject = 'javascript:window.location.href="%s"; '%uls 
            return javasinject 

    def jsinject(link): 
        str(link) 
        browser.runjs(link) 


    jsinject(str(getvideourl(browser.html))) 
    browser._wait_load()