Search code examples
pythonflashscreenshot

Screenshot of flash element in Python


How can I take a scrennshot of flash website in Python 3.5.1. I trying something like this but I can't see video image.

from selenium import webdriver

def webshot(url, filename):
    browser = webdriver.PhantomJS()
    browser.get(url)
    browser.save_screenshot(filename)
    browser.quit()

webshot('https://www.youtube.com/watch?v=YQHsXMglC9A', 'screentest.png')

Solution

  • Short version : With Youtube system, if you didn't press that "play" button (initiate playback) there is no video served. Loading the page via browser is a form of initiating playback too. However using a webshot doesn't fulfill Youtube server's requirements so it wont work.

    long version :

    How can I take a screenshot of a Flash website... I tried this but I can't see video image.
    webshot('https://www.youtube.com/watch?v=YQHsXMglC9A', 'screentest.png')

    You cannot screenshot Youtube's video player content like this. The way Youtube works is that when video page is ready, another PHP file is accessed to determine the video link (eg: the correct file for chosen quality settings, etc). Basically you have to appear to be like a browser making an HTTP request to their servers. Their server gives temporary token to access video link until token expires etc. There's other issues like CORS to deal with. These things are not being done by your tool.

    If only Youtube used a normal <video tag> with simple MP4 link then your code would've worked.

    The best you can get is like below (see how there is no controls?) using :

    webshot('https://www.youtube.com/embed/YQHsXMglC9A', 'screentest.png')