[PYTHON] [EC2] How to take a screen capture of your smartphone with selenium

[EC2] How to take a screen capture of your smartphone with selenium

Just add the UA for your smartphone to the options argument.

** ▼ For iphone safari **

Options to add


options.add_argument('--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1')

** ▼ Code example **

python


#-*- coding: utf-8 -*-

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

options = Options()
options.headless = True

#Specify the screen size to capture
options.add_argument('--window-size=412,732')
####driver.set_window_size(600,1000)

#Specify UA
options.add_argument('--user-agent=Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C92 Safari/602.1')

driver = webdriver.Chrome(options=options)

#Specify URL
driver.get("https://www.google.co.jp/")

#Specify the capture file name and extension
driver.save_screenshot('googletop-sp.png')


driver.quit()

## List of major user agents https://developers.whatismybrowser.com/useragents/explore/

Android(Google WebLight Proxy)

Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.19

image.png

Available for mobile and mobile phone.

iphone(Safari 13)

Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1

Recommended Posts

[EC2] How to take a screen capture of your smartphone with selenium
How to switch to smartphone mode with Python + Selenium + Chrome
How to display a list of installable versions with pyenv
[EC2] How to run selenium webdriver
How to determine the existence of a selenium element in Python
Here's a brief summary of how to get started with Django
Node.js: How to kill offspring of a process started with child_process.fork ()
[EC2] Introduction to scraping using selenium (text extraction and screen capture)
How to take a screenshot of the Chrome screen (prevent it from cutting off in the middle)
How to add a package with PyCharm
[Python] [Windows] Take a screen capture in Python
Build a capture acquisition machine with Selenium
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Summary of how to build a LAMP + Wordpress environment with Sakura VPS
How to calculate the volatility of a brand
How to read a CSV file with Python 2/3
A simple example of how to use ArgumentParser
How to send a message to LINE with curl
How to draw a 2-axis graph with pyplot
Bulk deployment with CFn to take a manual snapshot of Elasticsearch Service with Lambda
How to develop a cart app with Django
Find out how to divide a file with a certain number of lines evenly
How to make a dictionary with a hierarchical structure.
[EC2] How to deal with errors that selenium cannot execute (No module named selenium)
How to deal with SessionNotCreatedException when using Selenium
How to apply updlock, rowlock, etc. with a combination of SQLAlchemy and SQLServer
How to specify attributes with Mock of python
How to implement "named_scope" of RubyOnRails with Django
How to create a multi-platform app with kivy
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
A new form of app that works with GitHub: How to make GitHub Apps
How to identify the element with the smallest number of characters in a Python list?
A memo on how to overcome the difficult problem of capturing FX with AI
How to change the generated image of GAN to a high quality one to your liking
How to convert / restore a string with [] in python
A memo connected to HiveServer2 of EMR with python
A memo of how to use AIST supercomputer ABCI
[Python] How to draw a line graph with Matplotlib
How to create a submenu with the [Blender] plugin
How to get a logged-in user with Django's forms.py
How to convert a class object to a dictionary with SQLAlchemy
Take a screenshot of the LCD with Python-LEGO Mindstorms
How to make a shooting game with toio (Part 1)
How to write a list / dictionary type of Python3
How to output CSV of multi-line header with pandas
Python + selenium to GW a lot of e-mail addresses
How to infer MAP estimate of HMM with PyStruct
Basics of PyTorch (2) -How to make a neural network-
How to infer MAP estimate of HMM with OpenGM
Transit to the update screen with the Django a tag
How to take a captured image from a video (OpenCV)
[Python] How to create a 2D histogram with Matplotlib
How to learn structured SVM of ChainCRF with PyStruct
[Python] How to draw a scatter plot with Matplotlib
[Selenium] How to specify the relative path of chromedriver?
How to operate Firefox with selenium on Windows Memo
Summary of how to share state with multiple functions
[Linux] How to put your IP in a variable
How to debug selenium
How to plot a lot of legends by changing the color of the graph continuously with matplotlib