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.)
https://www.python.org/
Deployment target
Deployment destination
https://sites.google.com/a/chromium.org/chromedriver/
C:\00_myspace\tool\python-3.8.5-embed-amd64\driver\850418387
Command: wget "https://bootstrap.pypa.io/get-pip.py" -O "get-pip.py"
Command: python -m get-pip install selenium
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()
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
https://qiita.com/mm_sys/items/1fd3a50a930dac3db299 https://sites.google.com/a/chromium.org/chromedriver/getting-started
Recommended Posts