SHARE
TWEET

Selenium - remove header, footer and cookies message

furas Jul 15th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. # Header disappears only if I remove two elements.
  3. # Maybe there is better single selector which remove all.
  4. #
  5.  
  6. from selenium import webdriver
  7.  
  8. def fullpage_screenshot(driver, file):
  9.  
  10.     # header
  11.     elements = driver.find_elements_by_css_selector('div.metabar')
  12.     for item in elements:
  13.             driver.execute_script("arguments[0].remove()", item)
  14.  
  15.     # footer
  16.     elements = driver.find_elements_by_css_selector('div.u-fixed')
  17.     for item in elements:
  18.             driver.execute_script("arguments[0].remove()", item)
  19.  
  20.     # cookies message
  21.     elements = driver.find_elements_by_css_selector('div.butterBar')
  22.     for item in elements:
  23.             driver.execute_script("arguments[0].remove()", item)
  24.  
  25. # ------------
  26.  
  27. driver = webdriver.Chrome()
  28.  
  29. url = "https://towardsdatascience.com/object-detection-with-10-lines-of-code-d6cb4d86f606"
  30. driver.get(url)
  31. fullpage_screenshot(driver, "test1236.png")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top