采集base64图片

在采集图片时,图片以base64格式而不是路径地址加载时。

在内容过滤中运行C#代码

注:路径“D:\download\”可以修改,但是需要提前创建好文件夹。

using System;
using System.Collections.Generic;
using SpiderInterface;
class LocoyCode{
    /// <summary>
    /// 执行方法,不能修改类和方法名称。
    /// </summary>
    /// <param name="content">标签内容</param>
    /// <param name="response">页面响应,包含了Url、原始Html等属性</param>
    /// <returns>返回处理后的标签内容</returns>
    public string Run(string content,ResponseEntry response){        
            int start = content.IndexOf("/");
            int end = content.IndexOf(";");
            string ext = content.Substring(start + 1, end - start - 1);
            System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Png;

            switch (ext.ToLower())
            {
                case "bmp":
                    format = System.Drawing.Imaging.ImageFormat.Bmp;
                    break;
                case "emf":
                    format = System.Drawing.Imaging.ImageFormat.Emf;
                    break;
                case "wmf":
                    format = System.Drawing.Imaging.ImageFormat.Wmf;
                    break;
                case "gif":
                    format = System.Drawing.Imaging.ImageFormat.Gif;
                    break;
                case "jpg":
                    format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    break;
                case "png":
                    format = System.Drawing.Imaging.ImageFormat.Png;
                    break;
                case "tiff":
                    format = System.Drawing.Imaging.ImageFormat.Tiff;
                    break;
                case "exif":
                    format = System.Drawing.Imaging.ImageFormat.Exif;
                    break;
                case "icon":
                    format = System.Drawing.Imaging.ImageFormat.Icon;
                    break;
            }
            String filename =Guid.NewGuid().ToString() + "."+ext;
            String path="D:\\download\\" + filename;

            String base64 = content.Substring(content.IndexOf(",") + 1); 

            System.Drawing.Bitmap bitmap = null;

            try
            {
                String inputStr = base64;

                byte[] arr = Convert.FromBase64String(inputStr);

                using (System.IO.MemoryStream ms = new System.IO.MemoryStream(arr))
                {
                    using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms))
                    {
                        ms.Close();
                        bitmap = bmp;
                        bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Gif);
                    }
                }
            }
            catch (Exception)
            {
            }
            return filename;
    }
}

centos7.2+apache2.4.6+php7.2+mysql8

一、安装mysql8

1.卸载系统自带的mariadb-libs

rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

2.下载mysql8.0.12

wget https://centos.pkgs.org/7/centos-x86_64/libaio-0.3.109-13.el7.i686.rpm.html
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-server-8.0.12-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-libs-8.0.12-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-common-8.0.12-1.el7.x86_64.rpm
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-client-8.0.12-1.el7.x86_64.rpm

3.安装

yum install libaio
rpm -ivh mysql-*.rpm

4.修改认证方式

vi /etc/my.conf

去掉default-authentication-plugin=mysql_native_password前面的注释

5.将mysqld加入自动启动,启动mysqld

systemctl enable mysqld
systemctl start mysqld

6.获取临时密码登录

grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p

7.修改root密码(密码需要包含大小写字母、数字和特殊字符)

ALTER user 'root'@'localhost' IDENTIFIED BY '密码'

8.开启远程

update user set host='%' where user='root';

二、安装php7.2

1.更改yum源(webtatic访问不稳定,如果失败需要多尝试几次)

yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.安装php72w及扩展库

yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-curl php72w-json

3.将php-fpm加入自动启动,启动php-fpm

systemctl enable php-fpm
systemctl start php-fpm

三、安装apache

yum install -y httpd

在httpd.conf最后添加

<VirtualHost *:80>
        ServerName 域名
        ServerAlias     域名1 域名2
        DocumentRoot 站点路径
        DirectoryIndex index.php
    <Directory 站点路径>
        Options FollowSymLinks Indexes
        AllowOverride All
    </Directory>
</VirtualHost>

将httpd加入自动启动,启动httpd

systemctl enable httpd
systemctl start httpd