Do not want the Images to load and CSS to render on Firefox in Selenium WebDriver - Python

后端 未结 6 867
长情又很酷
长情又很酷 2020-11-29 00:37

I am using Selenium 2 with python bindings to fetch some data from our partner\'s site. But on an average it\'s taking me around 13 secs to perform this operation.

I

6条回答
  •  生来不讨喜
    2020-11-29 00:52

    Tossing in my 2¢.

    Better to use javascript snippets to accomplish.

    driver.execute_script(
       'document.querySelectorAll("img").forEach(function(ev){ev.remove()});'
    );
    

    That will remove the img elements. If you do this right after you load the page, they will have little chance to download image data.

    Here is a similar solution I found elsewhere on StackOverflow. (Can't find it anymore)

    driver.execute_script(
       "document.head.parentNode.removeChild(document.head)"
    );
    

提交回复
热议问题