2010-07-19 100 views

回答

3

獲得這兩個網站的格式化輸出(這裏我們使用w3m的,但山貓也能正常工作):

w3m -dump http://google.com 2>/dev/null > /tmp/1.html 
w3m -dump http://google.de 2>/dev/null > /tmp/2.html 

然後用wdiff,它可以給你的是如何相似的百分比這兩個文本是。

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到法國...搞笑)

common%值是兩個文本是多麼相似。另外,你可以很容易地通過單詞(而不是可能是混亂的線)看到差異。

+0

如果你只想要百分比,你可以執行以下命令:'wdiff -nis /tmp/1.html /tmp/2.html |尾-2 | awk'{print $ 5}'' – droope 2011-04-08 15:01:08

0

將文件複製到同一臺服務器中/tmp/directory1/tmp/directory2並運行以下命令:

diff -r /tmp/directory1 /tmp/directory2

對於所有意圖和目的,你可以把它們放在首選的位置,您的首選命名約定。

編輯1

你可能使用lynx -dumpwget和運行結果的差異。

+0

這不是比較文件本身不是嗎?我想通過Apache(和PHP)運行後比較呈現的頁面。我想我正在尋找某種網絡蜘蛛或爬蟲。 – 2010-07-19 21:37:46

2

捕獲是如何檢查'呈現'頁面。如果頁面沒有任何動態內容,最簡單的方法是使用md5或sha1命令爲文件生成散列,然後針對新服務器進行檢查。

這些網頁具有動態內容,你將不得不使用下載工具wget之類的網站

wget的--mirror http://thewebsite/thepages

,然後使用diff由華納的建議或做再次哈希的東西。我認爲差異可能是最好的方式,因爲即使改變1個字符也會混淆哈希。

+0

我在看到你的答案之前正在編輯。你提供了一個很好的建議。 – Warner 2010-07-19 21:44:29

0

缺乏渲染每個頁面,採取屏幕截圖和比較這些屏幕截圖,我不認爲有可能比較呈現的頁面。

但是,在用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. 

下一步將是做華納推薦的遞歸差異。

相關問題