我们正在迁移网站服务器,希望有一种自动化的方式来检查基本站点结构,以确定在新服务器上呈现的页面与旧服务器上的页面是否相同。我想知道是否有任何工具可以协助完成这个任务?
获取两个站点的格式化输出(这里我们使用w3m,但lynx也可以使用):
w3m -dump http://google.com 2>/dev/null > /tmp/1.html
w3m -dump http://google.de 2>/dev/null > /tmp/2.html
wdiff -nis /tmp/1.html /tmp/2.html
使用colordiff可能更容易看出差异。
wdiff -nis /tmp/1.html /tmp/2.html | colordiff
输出摘录:
Web Images Vidéos Maps [-Actualités-] Livres {+Traduction+} Gmail plus »
[-iGoogle |-]
Paramètres | Connexion
Google [hp1] [hp2]
[hp3] [-Français-] {+Deutschland+}
[ ] Recherche
avancéeOutils
[Recherche Google][J'ai de la chance] linguistiques
/tmp/1.html: 43 words 39 90% common 3 6% deleted 1 2% changed
/tmp/2.html: 49 words 39 79% common 9 18% inserted 1 2% changed
(他实际上把google.com翻译成了法语...很有趣)
常见的百分比值表示两个文本之间的相似程度。此外,您可以通过单词轻松地查看差异(而不是按行查看,这可能会使其混乱)。
除了渲染每个页面、截取屏幕并比较这些截图之外,我认为不可能比较已渲染的页面。
然而,通过使用wget递归下载后,比较已下载的网站是完全可能的。
wget [option]... [URL]...
-m
--mirror
Turn on options suitable for mirroring. This option turns on recursion and time-stamping, sets infinite recursion depth and keeps FTP
directory listings. It is currently equivalent to -r -N -l inf --no-remove-listing.
将文件复制到同一服务器的/tmp/directory1
和/tmp/directory2
中,并运行以下命令:
diff -r /tmp/directory1 /tmp/directory2
为了所有目的,您可以将它们放在您喜欢的位置并使用您喜欢的命名约定。
编辑1
您可以潜在地使用lynx -dump
或wget
并对结果运行差异。
wdiff -nis /tmp/1.html /tmp/2.html | tail -2 | awk '{print $5}'
。 - Pedro