Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
screenshot
#3
yes,i want to write code to take picture from page in define size.(mobile size and desktop size)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

# Provide a list of urls to create screenshots from
link = 'http://digikala.com'

# The Chrome and ChromeDriver Paths will vary based on your Operating System.
# This example shows how to configure ChromeDriver for Mac
CHROME_PATH = '/usr/bin/google-chrome-stable'
CHROMEDRIVER_PATH = '/home/arezoo/Desktop/chromedriver'

# Set the Browser Size
WINDOW_SIZE = "320,480"

# Configure Chrome Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.binary_location = CHROME_PATH

driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,
                          options=chrome_options)

# Loop through the list of urls and save the screenshot

driver.get(link)

# sleep for 2 seconds to allow the page to fully load.
time.sleep(2)

# create a clean filename from the url
str = link.split('://')[1]
filename = str.replace('/', '__')
image = filename.replace('.', '_') + ".png"

# save the screenshot
driver.save_screenshot(image)

# Close Selenium
driver.close()
Reply


Messages In This Thread
screenshot - by arezoo - Apr-11-2020, 09:53 AM
RE: screenshot - by buran - Apr-11-2020, 10:02 AM
RE: screenshot - by arezoo - Apr-11-2020, 10:17 AM
RE: screenshot - by buran - Apr-11-2020, 10:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Taking screenshot ConsistentlyInconsistent 1 1,160 Sep-10-2023, 11:20 PM
Last Post: Larz60+
  Flask Can't Save Screenshot to Postgres Db firebird 3 2,438 Sep-21-2020, 09:22 PM
Last Post: firebird
  Store Screenshot Selenium + MongoDB Nuwan16 9 3,709 Aug-18-2020, 03:57 AM
Last Post: ndc85430
  Screenshot web page ! ABVSVL 3 3,402 Jul-11-2020, 01:39 PM
Last Post: snippsat
  selenium screenshot hai001 18 14,173 Feb-25-2017, 06:22 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020