Chromedriver on Centos

运行微博爬虫始终提示

‘chromedriver’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/ch

试图通过yum –y install chromedriver阿里云匹配的chromedriver的版本低于chrome,需要更新。然后发现不管是更新chrome还是chromium,始终都存在着版本不对。直到找到了这个:

https://blog.csdn.net/herobacking/article/details/80276060

安装 chrome

使用下面的命令,在root用户下就可以安装最新的 Google Chrome:

yum –y install google-chrome-stable

安装 selenium

在 seleniump官网 找到最新的版本,下载selenium-server-standalone-X.XX.X.jar文件

selenium-server-standalone-3.13.0.jar

selenium服务初始化

将上述selenium放入一个文件夹中,输入如下命令初始化

java -jar selenium-server-standalone-3.13.0.jar

注意,需要 java8 环境,可以参考 CentOS7安装java运行环境jdk

安装 chromerriver

在 chromerriver官网下载最新的ChromeDriver压缩包,解压得到chromedriver.exe文件

chromedriver_linux64.zip

将下载的文件解压,放在如下位置

/usr/bin/chromedriver

给予执行权限

chmod +x /usr/bin/chromedriver

安装 XVFB

输入如下命令

yum install Xvfb -y  yum install xorg-x11-fonts* -y

新建在/usr/bin/ 一个名叫 xvfb-chrom 的文件写入以下内容:

vi /usr/bin/xvfb-chrome

#!/bin/bash    _kill_procs() {    kill -TERM $chrome    wait $chrome    kill -TERM $xvfb  }    # Setup a trap to catch SIGTERM and relay it to child processes  trap _kill_procs SIGTERM    XVFB_WHD=${XVFB_WHD:-1280x720x16}    # Start Xvfb  Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp &  xvfb=$!    export DISPLAY=:99    chrome –no-sandbox –disable-gpu$@ &  chrome=$!    wait $chrome  wait $xvfb

添加执行权限

chmod +x /usr/bin/xvfb-chrome

查看当前映射关系

ll /usr/bin/ | grep chrom

-rwxr-xr-x   1 root root   7874704 Mar 20 14:55 chromedriverlrwxrwxrwx   1 root root        31 Mar 20 00:24 google-chrome -> /etc/alternatives/google-chromelrwxrwxrwx   1 root root        32 Mar 20 14:30 google-chrome-stable -> /opt/google/chrome/google-chrome

更改Chrome启动的软连接

ln -s /etc/alternatives/google-chrome /usr/bin/chrome  rm -rf /usr/bin/google-chrome ln -s /usr/bin/xvfb-chrome /usr/bin/google-chrome

查看修改后的映射关系

ll /usr/bin/ | grep chrom

-rwxr-xr-x   1 root root   7874704 Mar 20 14:55 chromedriverlrwxrwxrwx   1 root root        31 Mar 20 00:24 chrome -> /etc/alternatives/google-chromelrwxrwxrwx   1 root root        22 Mar 20 00:11 google-chrome -> /usr/bin/xvfb-chromiumlrwxrwxrwx   1 root root        32 Mar 20 14:30 google-chrome-stable -> /opt/google/chrome/google-chrome-rwxr-xr-x   1 root root       432 Mar 20 00:09 xvfb-chrome

 

Solve AnacondaFailed toCreateMenus

This time I tried to solve a problem while installing Anaconda. My friend, a charming and talented lady, is interested in computer science. She wanted to learn python. So, I recommended Anaconda to her. It never occurred to me that there could be problems installing it. The failure is that ‘Anaconda failed to create menus.’

Answers from Github indicate there are many reasons, and the problem might be solved in the coming releases. They also presented many possible solutions. But most of them didn’t work. After trying again and again, I had to copy the complete folders to her installation and execute the following lines:

Firstly, go the Anaconda/Script, input ‘conda update conda’,

Then, go to Anacnoda/Lib, input ‘..python _nsis.py mkmenus’,

And problem solved. Thanks to

Update WordPress

The website reminded me about a new version had been launched. So I clicked Update. I expected it to finish updating quickly. And it did, with an error of unable to write folder. Initially, I thought it should be the problem of ‘Group’. I added a new group, changed the permissions and assigned the files to the group. No use. Then, I changed the files to 777, yet it did not work, either.

I decided to update it manually. The following two methods are tested. The first method was to download and upload the latest version through SSH, which was too slow, not to mention the network. All these led to the second method of the following lines:

  1. wget http://wordpress.org/latest.zip
  2. unzip latest.zip
  3. rm –rf wordpress/wp-content /var/www/html/wp-admin /var/www/html/wp-includes
  4. mv wordpress/* /varwww/html/
  5. rm –rf wordpress

Remember, before the commands executed, the important files are backed up.

Later, I found that it was actually very simple.

chown -R apache:apache /*/*/wp-content

Visualize Famous Campus in China

In the end of the 9th month of 2017, many great events happened. One influential thing is the launch of the country’s construction plan of world first-class universities and world first-class disciplines. The plan, also known as the “Double-First Class” initiative, really inspires scholars and researchers. Honestly, I felt sad when HNU got categorized as B in the list. But as the saying goes, be aware of shame then go forward. I decided to visualize the famous campus surroundings. In the near future, the codes will be available on GitHub soon. Now I just show some results within an 800 m circle centered by the Department of Civil Engineering.
First the campus of HNU, the points are quite abstract. But for anyone who has lived there, the basic layout has been clearly drawn. Obviously, the campus area of HNU is quite small.

I posted the images here:

https://yq.aliyun.com/articles/620469

Install WordPress on Centos

Before beginning, a domain, an ESC or a VPS are needed. Once the ECS or the VPS and the domain are prepared, the following procedures can be conducted.

Detailed steps are as followings:

  • Install LAMP services (Linux, Apache, MySQL, PHP).

input these commands:

  1. Install Apache, MySQL, and PHP

yum -y install httpd mysql mysql-server php php-mysql php-gd php-xml

  1. Set up httpd and mysqld to start with system

systemctl enable httpd.service

“””

Updated on 7.26.2018 mysqld.service failed to start.

yum install mariadb-server -y

systemctl start mariadb.service

systemctl enable mariadb.service

“””

  1. Start services

systemctl restart httpd.service
systemctl restart mariadb.service

  1. Set up MySQL

mysql_secure_installation
Set root password? [Y/n] // (Y)
Remove anonymous users? [Y/n] // (Y)
Disallow root login remotely? [Y/n] //(n)
Remove test database and access to it? [Y/n] //(Y)
Reload privilege tables now? [Y/n] //(Y)
login MySQL: mysql -u root -p  (the password is empty, just press enter)

mysql> create database wordpress; //create a database and name it as ‘wordpress’

  • Install WordPress
  1. Download and Install

wget http://wordpress.org/latest.zip  //download wordpress
unzip latest.zip  // uncompress file
cp -r wordpress/* /var/www/html/jmli //move files under floder ‘wordprss’to apache

2、Set up WordPress

cd /var/www/html
cp wp-config-sample.php wp-config.php
vim wp-config.php

Press ‘i’ to write, insert database name, user name and user password. Others remain the same.

Press ‘Esc’ to exit writing mode. Double press ‘Shift’ + ‘z’ to exit the file.

Then, go to your domain to finish WordPress set up.

I used Wanwang to register a domain and Aliyun to set up an ECS. The discounts for students and Double 11th are very attractive. As for the other services in its store, I have not used them yet.