Python script to make screenshots of a website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cloner.py 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. from selenium import webdriver #Control libryry for Firefox
  3. from selenium.webdriver.firefox.options import Options #Options library for firefox
  4. from openpyxl import load_workbook #library for reading excel tables
  5. import os #For checking if File exists
  6. import sys #For getting the Path of the file.
  7. runfirefoxheadless = False #set True to disable the Firefox GUI
  8. filename = "Linkliste.xlsx" #excel File which includes the link (example design is at the bottom. Starts reading from line 2)
  9. sheetname = "Linkliste" #name of the Sheet in the Excel file
  10. adblockplusfilename = "adblock.zip" #adblockplus file must be located in the Script Folder.
  11. adblockplusdownloadlink = "https://nextcloud.jonasled.de/index.php/s/xQWLPxzFYwWEFE2/download" #Downloadlink if ABP was not found. This is a modified version, which won't show the Welcome message.
  12. if(os.name == "nt"): #On Windows use \ to seperate Folders and on Linux /.
  13. abp_path = os.path.dirname(sys.argv[0]) + "\\" + adblockplusfilename
  14. else:
  15. abp_path = os.path.dirname(sys.argv[0]) + "/" + adblockplusfilename
  16. if not (os.path.exists(abp_path)): #Check if the ABP Plugin exists. If not it will download it
  17. print("Adblock Plus not found, downloading")
  18. import requests
  19. r = requests.get(adblockplusdownloadlink)
  20. open(abp_path, 'wb').write(r.content)
  21. #Prepare the Firefox for use (start and install ABP Plugin)
  22. print("starting firefox")
  23. options = Options()
  24. options.log.level = "fatal"
  25. options.headless = runfirefoxheadless
  26. driver = webdriver.Firefox(options=options)
  27. print("installing adblock plus")
  28. driver.install_addon(abp_path, temporary=True)
  29. #Load Excel Table
  30. wb = load_workbook(filename)
  31. sheet_ranges = wb[sheetname]
  32. row = 2
  33. #Look in every line and download URL, if not already exists.
  34. while True:
  35. if not (os.path.exists("Websites/" + str(sheet_ranges['A' + str(row)].value) + ".png")):
  36. print("Getting " + sheet_ranges['B' + str(row)].value)
  37. driver.set_window_size(1080, 100)
  38. if(str(sheet_ranges['B' + str(row)].value)[0:4] == "http"): #Check if link starts with http(s), if not add it.
  39. driver.get(sheet_ranges['B' + str(row)].value)
  40. else:
  41. driver.get("http://" + sheet_ranges['B' + str(row)].value)
  42. width = driver.execute_script("return Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);")
  43. height = driver.execute_script("return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);")
  44. driver.set_window_size(width+100, height+100)
  45. driver.save_screenshot("Websites/" + str(sheet_ranges['A' + str(row)].value) + ".png")
  46. else:
  47. print("Skipping " + sheet_ranges['B' + str(row)].value)
  48. row = row + 1
  49. if(sheet_ranges['B' + str(row)].value == None):
  50. break
  51. driver.quit()
  52. #Example Excel table layout
  53. #Filename Link
  54. #google google.de
  55. #homepage https://jonasled.de