Environment construction procedure to operate chrome without installing python on Windows (using selenium)

Overview

There was a scene where it would be better to automate the browser at work. However, Windows lent by the company cannot freely install software. Therefore, it was necessary to automate without installing the software. So, I downloaded Python from Zip and installed Selenium there to build the execution environment. The procedure at that time is described below. (It may be difficult in an environment where the proxy server is restricted.)

procedure

1. Download the python zip

1-1. Access https://www.python.org/

https://www.python.org/

1-2. Downloads → Click Windows

image.png

1-3. Click the latest version

image.png

1-4. Scroll to the bottom and click "Windows x86-64 embeddable zip file"

image.png

1-5. Extract Zip to an appropriate folder (this time, extract it to C: \ 00_myspace \ tool )


Deployment target
image.png
Deployment destination
image.png

2. Rewrite "python38._pth" so that selenium can be installed

2-1. Delete the comment out of import

Change before

image.png

After change

image.png

3. Download the chrome driver

3-1. Check the chrome version

image.png

3-2. Access https://sites.google.com/a/chromium.org/chromedriver/

https://sites.google.com/a/chromium.org/chromedriver/

3-3. Click the same version of Chrome you confirmed (this time, select 85.0.4183.87)

image.png

3-4. Click chromedriver_win32.zip

image.png

3-5. Create a driver folder + version folder in the python folder you extracted earlier, and store the downloaded driver in it.

C:\00_myspace\tool\python-3.8.5-embed-amd64\driver\850418387 image.png

4. Install selenium

4-1. Start powershell

image.png

4-2. Move to the folder where python is installed

image.png

4-3. Download pip with wget "https://bootstrap.pypa.io/get-pip.py" -O "get-pip.py"

Command: wget "https://bootstrap.pypa.io/get-pip.py" -O "get-pip.py" image.png

4-4. Run python get-pip.py (maybe you don't have to)

image.png

4-5. Start the command prompt, move to the folder where python is installed, and execute the following command

Command: python -m get-pip install selenium image.png

4-6. Create a folder in the python folder to store the program for python

4-7. Store the sample file (chrome.py)

chrome.py


import time
from selenium import webdriver

#Load the driver
driver = webdriver.Chrome('./driver/850418387/chromedriver')
#Set google URL
driver.get('http://www.google.com/')
#1 second sleep (There is no point in putting sleep. I put it for technical notes)
#Specify search box
search_box = driver.find_element_by_name('q')
#search_box.send_keys('Narita Dream Farm Auto Campground')
#Search word setting in the search box
search_box.send_keys('yahoo')
#Search execution
search_box.submit()
#Select the first search result
search_box = driver.find_element_by_class_name('LC20lb')
#click
search_box.click()
#Get a list of classes specified in yahoo news etc.
search_box = driver.find_elements_by_class_name('_2bBRLhI5ZpVYu0tuHZEFrn')
#Click yahoo news
search_box[9].click()
print('Exit the browser after 10 seconds.')
#10 seconds sleep
time.sleep(10)
#Exit (close the browser)
driver.quit()

image.png

5. Execute (eg search yahoo on google and go to yahoo news page)

5-1. At the command prompt, move to the Python folder and execute the following command

Command: python ./pyfile/chrome.py

The above is the procedure for automating without installing python on Windows.

Github https://github.com/KOJI-YAMAMOTO-GitHub/python-selenium-chrome-sample

Reference site

https://qiita.com/mm_sys/items/1fd3a50a930dac3db299 https://sites.google.com/a/chromium.org/chromedriver/getting-started

Recommended Posts

Environment construction procedure to operate chrome without installing python on Windows (using selenium)
Python environment construction procedure memo using Docker on Windows10 Home
Python environment construction memo on Windows 10
Anaconda python environment construction on Windows 10
Python project environment construction procedure (for windows)
Use without installing python 2.x on Windows
Notes on installing Python3 and using pip on Windows7
python windows environment construction
Procedure for building a CDK environment on Windows (Python)
Procedure to exe python file from Ubunts environment construction
How to operate Firefox with selenium on Windows Memo
Python environment construction (Windows10 + Emacs)
Start to Selenium using python
Anaconda3 python environment construction procedure
Build Python environment on Windows
Build python environment on windows
Python environment construction under Windows7 environment
[Tensorflow] Tensorflow environment construction on Windows 10
OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)
Memo of Linux environment construction using VirtualBox + Vagrant on Windows 10
How to run Python on Windows without polluting the environment as much as possible (Scoop edition)
How to manage Python minor version (build virtual environment) on Windows (without Pyenv or WSL)
Python 3.6 on Windows ... and to Xamarin.
Installing Kivy on Windows10 64bit Python3.5
Install python2.7 on windows 32bit environment
Python environment construction memo on Mac
[Python3] Development environment construction << Windows edition >>
Installing Kivy-Designer on Windows10 64bit Python3.5
Python development environment construction on macOS
Notes on installing Python using PyEnv
Environment construction of python3.8 on mac
Install Python development environment on Windows 10
Python3.6 environment construction (using Win environment Anaconda)
OpenCV3 & Python3 environment construction on Ubuntu
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Everything from building a Python environment to running it on Windows
Building a Python development environment on Windows -From installing Anaconda to linking Atom and Jupyter Notebook-
I want to automatically operate Chrome on Windows from a virtual machine (ubuntu) started using Vagrant
Notes for using OpenCV on Windows10 Python 3.8.3.
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Using venv in Windows + Docker environment [Python]
[Kivy] How to install Kivy on Windows [Python]
[Python] Road to snake charmer (1) Environment construction
Steps to create a Python virtual environment with VS Code on Windows
Steps to install Python environment on Ubuntu
Creating a python virtual environment on Windows
VScode environment construction (Windows10, Python, C ++, C, Git)
Try to operate Excel using Python (Xlwings)
Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid
Windows + gVim + Poetry python development environment construction
I want to use Python in the environment of pyenv + pipenv on Windows 10
How to build an environment for using multiple versions of Python on Mac
To avoid seeing hell when installing django-toolbelt on windows, heroku and python3.4 (64bit) ...
Selenium + WebDriver (Chrome) + Python | Building environment for scraping
VS Code + Azure Functions + Python environment construction procedure
[Note] Python environment construction on rental server "CORESERVER"
Put MicroPython on Windows to run ESP32 on Python
Procedure to use TeamGant's WEB API (using python)
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Simply build a Python 3 execution environment on Windows