Disable styling on Google Search with Selenium FirefoxDriver

后端 未结 2 1096
遥遥无期
遥遥无期 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:59

    run the following javascript through the selenium script executor

    var queries = ['link[rel=stylesheet][href]', 'style'];
    for (var i = 0; i < queries.length; i++) {
        var remove = document.querySelectorAll(queries[i]);
        for (var j = 0; j < remove.length; j++) {
            remove[j].outerHTML = '';
        }
    }
    var inline = document.querySelectorAll('*[style]');
    for (var i = 0; i < inline.length; i++) {
        inline[i].removeAttribute('style');
    }
    

    I have tested this with google, it works. got the above script from this firefox extension code

    driver = webdriver.Firefox(firefox_profile)
    driver.get('http://www.google.com/')
    driver.execute_script("")
    

提交回复
热议问题