2013-07-16 74 views
2

我想比較Html文檔天氣有相同的標籤具有相同的安排,無論不同的內部文本和屬性值是不同的。我只想比較一般的標籤結構。如html文檔比較

<html> 
<head> 
</head> 
<body> 
<span class="my paragraph">comparison of general tag structure of html</span> 
</body> 
</html> 

<html> 
<head> 
</head> 
<body> 
<span class="Mega Offer">free membership offer</span> 
</body> 
</html> 

相同

<html> 
<head><title>Different</title> 
</head> 
<body> 
<span class="my paragraph">comparison of general tag structure of html</span> 
</body> 
</html> 

不一樣的,因爲沒有在標籤HTML結構中的一個額外的標題標籤,無論內在價值的屬性值相同。

+0

你只想知道他們是不同的還是你也想知道其中的區別?我認爲在這兩種情況下將html文檔解析爲XML都會有所幫助。 –

+0

是的,我也想知道區別。 –

+0

輸出應該有什麼區別? –

回答

0

如果你願意使用PHP,有幾個功能,如preg_match,將尋找模式。您可以使用file將html文件讀取到數組中,每個新行都是數組中的另一個條目。然後對其他html文件執行相同的操作。然後,您可以搜索第一個標籤(又名:以<開頭的內容)並讀取該行的其餘部分,直到>。然後去搜索另一個html文件中的相同標籤,計算該標籤出現的次數。沖洗並重復。