如何比较两个网页的布局和内容是否相同?

How do I compare whether two web pages have the same layout and content?

两个网址

http://www.bbprescott.com/

https://www.bbprescott.com/

虽然一个以"http://"开头,一个以"https://"开头,但内容相同。我怎样才能自动比较它们,而不是手动检查它们,一个脚本 returns 如果它们具有相同的内容则为真,如果它们不相同则为假。

我的回答基于此link

您可以根据需要进行调整

创建一个名为 myscript.sh 的文件,内容如下:

#!/bin/sh
wget --output-document=url_http.html http://www.bbprescott.com/
wget --output-document=url_https.html https://www.bbprescott.com/

diff --brief url_http.html url_https.html >/dev/null
comp_value=$?

if [ $comp_value -eq 1 ]
then
    echo "The two web pages are different"
else
    echo "The two web pages are identical"
fi

rm -f url_http*.html

然后在命令行上为您的登录用户添加执行权限:

chmod u+x myscript.sh

然后执行:

./myscript.sh

如果你想看到你的两个url内容之间的差异,你可以手动执行:

wget --output-document=url_http.html http://www.bbprescott.com/
wget --output-document=url_https.html https://www.bbprescott.com/
diff url_http.html url_https.html