Disable styling on Google Search with Selenium FirefoxDriver

后端 未结 2 1098
遥遥无期
遥遥无期 2021-02-09 05:36

The following code disables stylesheets and images on a page loaded with Selenium Firefox webdriver:

from selenium import webdriver

firefox_profile = webdriver.         


        
2条回答
  •  滥情空心
    2021-02-09 05:51

    The google logo come form the css, where the pictures are embedded in the HTML as data (img src="data:image/jpeg;base64, ....) the code disable the loading of remote images not this type of sources

    • permissions.default.stylesheet: disable any formatting

    • permissions.default.image: disable any image and css background-image

    if the image is embedded into the page as base64 encoded is not blocked by these permissions because is part of the HTML code (see http://en.wikipedia.org/wiki/Data_URI_scheme)

    to disable more formatting you should add:

    • firefox_profile.set_preference("permissions.default.script", 2);
    • firefox_profile.set_preference("javascript.enabled", False);

提交回复
热议问题