Screenshot web page ! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Screenshot web page ! (/thread-28236.html) |
Screenshot web page ! - ABVSVL - Jul-10-2020 How to take a screenshot from a website? the visible part of the site I can take a screenshot. How can I take a screenshot of an entire page (which scroll by scroll)? RE: Screenshot web page ! - snippsat - Jul-10-2020 (Jul-10-2020, 03:57 PM)ABVSVL Wrote: How can I take a screenshot of an entire page (which scroll by scroll)?Can call window.scrollTo() in Selenium.To take a random page as example,so can try to figure out how much to scroll(i take a guess on 800 here) before taking new screenshot. Turn of --headless as i use here can also help to see what's going on.from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument("--headless") options.add_argument("window-size=1920,1080") browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options) browser.get('https://www.tesmanian.com/blogs/tesmanian-blog') browser.save_screenshot("page1.png") browser.execute_script("window.scrollTo(0, 800);") browser.save_screenshot("page2.png") browser.close() RE: Screenshot web page ! - ABVSVL - Jul-11-2020 I try do it from selenium import webdriver # $ pip install selenium from selenium.webdriver.chrome.options import Options DRIVER = 'C:\selenium\chromedriver.exe' driver = webdriver.Chrome(DRIVER) options = webdriver.ChromeOptions() options.add_argument('headless') options.add_argument(f'window-size={1920},{1080}') options.add_argument('hide-scrollbars') # get chromedriver fro # https://sites.google.com/a/chromium.org/chromedriver/downloads browser = webdriver.Chrome(chrome_options=options) browser.get('stackoverflow.com') browser.save_screenshot('filename.png') but I have an error ========================================================================== C:\Users\Professional\PycharmProjects\automtest\venv\Scripts\python.exe C:/Users/Professional/PycharmProjects/automtest/diferents.py C:/Users/Professional/PycharmProjects/automtest/diferents.py:13: DeprecationWarning: use options instead of chrome_options browser = webdriver.Chrome(chrome_options=options) Traceback (most recent call last): File "C:\Users\Professional\PycharmProjects\automtest\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env, File "C:\Program Files (x86)\python\lib\subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Program Files (x86)\python\lib\subprocess.py", line 1307, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/Professional/PycharmProjects/automtest/diferents.py", line 13, in <module> browser = webdriver.Chrome(chrome_options=options) File "C:\Users\Professional\PycharmProjects\automtest\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__ self.service.start() File "C:\Users\Professional\PycharmProjects\automtest\venv\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home Process finished with exit code 1 RE: Screenshot web page ! - snippsat - Jul-11-2020 Use code tags Do not use \ in file path on Windows because of escape character ,see that i use r r'path' Use my code and not the older stuff that you use,then is like this. from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') ABVSVL Wrote:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.This mean that chromedriver.exe most be in Environment Variables Path.So i have have added this myself to Path C:\cmder\bin\chromedriver.exe .Just copy all of my code and make or use a Path that's in Environment Variables Path. Or this also work,copy code and remove path: from selenium import webdriver from selenium.webdriver.chrome.options import Options import time options = Options() #options.add_argument("--headless") #options.add_argument("window-size=1920,1080") browser = webdriver.Chrome(executable_path=r'chromedriver.exe', options=options) browser.get('https://www.tesmanian.com/blogs/tesmanian-blog') browser.save_screenshot("page1.png") time.sleep(5) browser.execute_script("window.scrollTo(0, 800);") browser.save_screenshot("page2.png") time.sleep(5) browser.close()Now have files in same folder,eg make a folder my_sel .Here also comment out --headless and add som time sleep then it easier to see how window.scrollTo() work.C:\my_sel\ |-- sel_screenshot.py |-- chromedriver.exe |