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

两个网址

http://www.bbprescott.com/

https://www.bbprescott.com/

具有相同的内容,尽管一个以“ http://”开头,另一个以“ https://”开头。与其手动检查它们,不如我如何自动比较它们:一个脚本,如果它们具有相同的内容,则返回true;否则,返回false。

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

我的回答基于此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
本文链接:https://www.f2er.com/3162254.html

大家都在问