Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faking Flash plugin info in PhantomJS and Python

I'm a newbie to PhantomJs. I'm using phantomjs via selenium webdriver with python as my language. I want to fake my flash plugins info which is very visible using javascript.

I want to do something like this(done in javascript) in Python using selenium webdriver.

page.onInitialized = function () {
page.evaluate(function () {
    (function () {
        window.navigator.plugins = {
            'length': 1, 
            'Shockwave Flash': {
                'description':'fakeflash'
            }
        };
    })();
});
};

I don't know how to implement page.onInitialized and other functions in Python(with selenium webdriver) Any help will be appreciated.

like image 831
user3210652 Avatar asked May 26 '26 15:05

user3210652


1 Answers

Personally, I couldn't find a way to get this to work either, so I instead went with using Firefox via selenium webdriver with gnash installed as a flash plugin. I know this is not quite what you are looking for, but it does have the desired effect in the end, as long as you have the system memory to support it.

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get(url)
print browser.page_source
browser.quit()
display.stop()

Or to be more safe (and never leave behind nasty Xvfb and firefox processes!):

from pyvirtualdisplay import Display
from selenium import webdriver

try:
    display = Display(visible=0, size=(800, 600))
    display.start()
    browser = webdriver.Firefox()
    browser.get(url)
    print browser.page_source
finally:
    if browser:
        browser.quit()
    if display:
        display.stop()

I suppose it could be done with Chrome in a virtual display as well. If someone ever does share the magic to let webdriver.PhantomJS preload in a flash faker for us, I'd be happy to switch over as it has far less system resource requirements.

like image 125
Beirdo Avatar answered May 28 '26 04:05

Beirdo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!