[PYTHON] What happens to the access log when the website is automatically accessed by selenium-webdriver

Purpose

Actually, I was secretly automating a part of the internal work, but when I looked into the server log, I thought that it would be possible to automate it, so I tried to verify it.

Verification environment

What i did

Introducing Selenium and Headless Chrome

There are many articles about this, so I will omit it.

Set up a web server

Go to PaizaCloud and log in. You can log in with your Google account, etc., and some plans can be used free of charge. This time I am using this free plan.

On the server creation screen, select an appropriate server name and application to install. This time I have Apache installed. image.png

After creating the server, click the browser button on the left to launch the internal browser. image.png

Of course, you can copy and paste the URL and use another browser. For the time being, I was able to confirm that the server was up.

Check the location of the server log

The Apache server log is located at /var/log/apache2/access.log by default. Click the console button on the left to launch the console. image.png

Hit the following command to check the access log.

sudo tail /var/log/apache2/access.log

This time, there was no access log yet.

Write code in python

main.py


#Module import
from selenium import webdriver

#Launch Chrome
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)

#Make a request to the web server
driver.get('https://bowtin-testserver.paiza-user.cloud/')

When you run the above program, Google Chrome should automatically launch and access the web page.

Check the access log

Check the access log on the server side again. image.png

It says Chrome, and at this point I don't know if it's manual or automatic.

Try changing the code so that the Chrome screen does not start

Add some code to get Chrome to start in the background. With this, Chrome is not displayed on the screen, so it feels like it is automated.

main.py


#Module import
from selenium import webdriver

#Launch Chrome
options = webdriver.ChromeOptions()
options.add_argument('--headless') #add to
options.add_argument('--disable-gpu') #add to
driver = webdriver.Chrome(options=options)

#Make a request to the web server
driver.get('https://bowtin-testserver.paiza-user.cloud/')

After modifying the code, run it again.

Check the server log again

This time, I was able to confirm that the browser type is Headless Chrome.

image.png

Conclusion

Recommended Posts

What happens to the access log when the website is automatically accessed by selenium-webdriver
Automatically acquire the operation log in the terminal when logging in to Linux
Animate what happens in frequency space when the Nyquist frequency is exceeded
What to do when the value type is ambiguous in Python?
What to do when the result downloaded via scrapy is in English
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
When the log acquired by rsyslog is not updated after rotation with logrotate
What to do when is not in the sudoers file.This incident will be reported.
What to do when only the window is displayed and nothing is displayed in pygame Note
[Introduction to Python] What is the important "if __name__ =='__main__':" when dealing with modules?
curl: (60) What to do when Issuer certificate is invalid.
Workaround when Authentication Required is displayed when trying to view the HDD by USB booting Linux
What to do when PyCharm font is strange or garbled
How to log in automatically like 1Password from the CLI
Change the installation destination when --user is added to pip
[Pyro] Statistical modeling by the stochastic programming language Pyro ① ~ What is Pyro ~
I tried to output the access log to the server using Node.js
What to do when a part of the background image becomes transparent when the transparent image is combined with Pillow