想要整站克隆某个站点,有一些已有的工具。

WGET

参考这篇文章( Make Offline Mirror of a Site using wget ) ,克隆网站可以直接使用wet命令

1
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent http://example.org

短命令

1
wget -mkEpnp http://example.org

效果还可以,中文编码处理可能会有点问题。

webhttrack

1
2
apt-get install -y webhttrack
主导Windows平台,Linux平台运行直接报错了,没有继续尝试

httrack

https://www.kali.org/tools/httrack/

1
2
apt install httrack
httrack http://140.143.242.46/

不会自己新建目录,所以要进入到要存放站点的文件夹下,再运行。

GitHub action

用法:在github repo根目录下编辑 urls.txt 文件,格式为

1
2
[URL] [dir name] [comment]
https://www.yinwang.org/ www.yinwang.org 王垠博客:当然我在扯淡 

会以 www.yinwang.org 为目录克隆 https://www.yinwang.org/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: clone site

on:
  workflow_dispatch:
  push:
    branches:
      - master
    paths:
      - '**/urls.txt'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: do the work
        run: |
          set -ex
          echo "### setting up git repo and pushing change... ###"
          pwd
          ls -lhA
          sudo timedatectl set-timezone "Asia/Shanghai"
          mkdir -p ~/.ssh/
          echo "${{ secrets.SITECOPY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          git config --global user.email "ci@github.io"
          git config --global user.name "ci"
          
          git clone git@github.com:findneo/sitecopy.git
          cd sitecopy
          
          echo "### cloning website ... ###"
          #sudo apt install -y wget 
          #wget --mirror --convert-links --adjust-extension --page-requisites --no-parent $(tail -n1 urls.txt|cut -d " " -f1) >res.txt
          sudo apt update -y
          sudo apt install -y httrack 
          mkdir $(tail -n1 urls.txt|cut -d " " -f2)
          cd $(tail -n1 urls.txt|cut -d " " -f2)
          httrack $(tail -n1 ../urls.txt|cut -d " " -f1)
          cd ..
          echo "### cloning website done ###"
          echo "### push changes ###"
          
          
          git add -A
          git commit -m "update  site" --allow-empty
          git push
          rm -rf ~/.ssh/