I tried to make a periodical process with Selenium and Python

I've only written a blog full of anime material, I will also post it as a memorandum.

In the first place, the reason for trying to create a periodical execution process was I'm doing the same thing every week on a website, can you do it automatically? Because of the request.

So

Purpose

What is used for periodic execution processing

Create test cases for Python with Selenium IDE (Windows or Mac, etc.)

  1. Install Selenium IDE on Firefox
  2. Record the steps you want to take automatically on your website with Selenium IDE
  3. Export test cases => Python 2 / unittest / WebDriver
  4. Upload the saved test case to CentOS

Environment construction for periodic processing (CentOS)

Python package management system installation


yum install python-pip

Python Selenium installation


pip install selenium

Firefox installation


yum install firefox

Xvfb installation


yum install xorg-x11-server-Xvfb

Create Xvfb auto-start service


vi /etc/init.d/xvfb

/etc/init.d/xvfb


#!/bin/bash
#
# chkconfig: - 91 35
# description: Xvfb

# Source function library.
. /etc/init.d/functions

# Xvfb define
readonly XVFB=/usr/bin/Xvfb
readonly XVFB_STATUS=":1 -screen 0 1366x768x24"
readonly XVFB_PID_FILE=/var/run/xvfb.pid
readonly XVFB_SERVICE=$"Xvfb"

retval=0

start() {
    if [ -e ${XVFB_PID_FILE} ]; then
        action $"Starting ${XVFB_SERVICE}: " /bin/false
        echo "${XVFB_SERVICE}Is already running."
    else
        action $"Starting ${XVFB_SERVICE}: " /bin/true
        ${XVFB} ${XVFB_STATUS} > /dev/null 2>&1 &
        echo $! > ${XVFB_PID_FILE}
    fi
}

stop() {
    if [ -e ${XVFB_PID_FILE} ]; then
        action $"Stopping ${XVFB_SERVICE}: " /bin/true
        pid=`cat ${XVFB_PID_FILE}`
        test ! -z $pid && kill $pid && rm -f ${XVFB_PID_FILE}
    else
        action $"Stopping ${XVFB_SERVICE}: " /bin/false
        echo "${XVFB_SERVICE}Is not running."
    fi
}

status() {
    if [ -e ${XVFB_PID_FILE} ]; then
        echo "${XVFB_SERVICE} (pid `cat ${XVFB_PID_FILE}`)Is running..."
    else
        echo "${XVFB_SERVICE}Is not running."
    fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 1
        start
        ;;
    status)
        status
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        retval=1
esac

exit ${retval}

Xvfb auto-start service settings


chmod 755 /etc/init.d/xvfb
chkconfig --add xvfb
chkconfig --level 3 xvfb on

Xvfb reboot


/etc/init.d/xvfb restart

Periodic execution process creation


crontab -e

cron


#Specify e-mail address for checking cron execution result
[email protected]
# /home/kotanbo/test.The py part specifies the uploaded test case
#The following is regularly executed at 9 o'clock on Sunday
0 9 * * 0 export DISPLAY=localhost:1.0; python /home/kotanbo/test.py

cron restart


/etc/init.d/crond restart

reference

Ruby + selenium-webdriver in Linux CUI environment Xvfb startup script [Automatically start selenium server on centos](http://hironoki.com/blog/2011/10/28/centos%E3%81%A7selenium%E3%82%B5%E3%83%BC%E3%83%90 % E3% 83% BC% E8% 87% AA% E5% 8B% 95% E8% B5% B7% E5% 8B% 95 /)

Postscript

2017/04/27

The latest firefox and selenium probably won't work with the above. I have described the contents of the newly constructed environment, so please also check it out. => I made a periodical execution process with CentOS7, Selenium, Python and Chrome

Recommended Posts

I tried to make a periodical process with Selenium and Python
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
I tried to make GUI tic-tac-toe with Python and Tkinter
[5th] I tried to make a certain authenticator-like tool with python
[2nd] I tried to make a certain authenticator-like tool with python
[3rd] I tried to make a certain authenticator-like tool with python
I tried to make a 2channel post notification application with Python
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
I want to make a game with Python
Python: I tried to make a flat / flat_map just right with a generator
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I tried to draw a route map with Python
I tried to automatically generate a password with Python3
I tried to make a simple mail sending application with tkinter of Python
[Patent analysis] I tried to make a patent map with Python without spending money
[ES Lab] I tried to develop a WEB application with Python and Flask ②
I tried to easily create a fully automatic attendance system with Selenium + Python
I tried to make a simple image recognition API with Fast API and Tensorflow
I tried to make various "dummy data" with Python faker
I tried to make a stopwatch using tkinter in python
I tried to automate the article update of Livedoor blog with Python and selenium.
Fractal to make and play with Python
I tried a functional language with Python
I tried to make a Web API
Rubyist tried to make a simple API with Python + bottle + MySQL
A memorandum when I tried to get it automatically with selenium
I tried to make a regular expression of "amount" using Python
[Python] I tried to implement stable sorting, so make a note
I tried to make a regular expression of "time" using Python
[Python] A memo that I tried to get started with asyncio
How to make a surveillance camera (Security Camera) with Opencv and Python
I tried to create a list of prime numbers with python
I tried to make a regular expression of "date" using Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I tried to create Bulls and Cows with a shell program
I tried to easily detect facial landmarks with python and dlib
I tried to make a strange quote for Jojo with LSTM
I tried to make an image similarity function with Python + OpenCV
I tried to make a mechanism of exclusive control with Go
[1 hour challenge] I tried to make a fortune-telling site that is too suitable with Python
I made a server with Python socket and ssl and tried to access it from a browser
I tried to make a generator that generates a C # container class from CSV with Python
I also tried to imitate the function monad and State monad with a generator in Python
I want to make a voice changer using Python and SPTK with reference to a famous site
I tried web scraping using python and selenium
I tried Jacobian and partial differential with python
I tried to get CloudWatch data with Python
Try to make a "cryptanalysis" cipher with Python
I tried function synthesis and curry with python
I tried to output LLVM IR with Python
I tried to automate sushi making with python
Try to make a dihedral group with Python
I want to write to a file with Python
I tried to make a ○ ✕ game using TensorFlow
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
[AWS] [GCP] I tried to make cloud services easy to use with Python
I tried to discriminate a 6-digit number with a number discrimination application made with python
[Outlook] I tried to automatically create a daily report email with Python