我想比较 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结构中多了一个title标签,无论内部值和属性值是否相同。
最佳答案
如果您愿意使用 php,有几个函数,例如 preg_match那将寻找模式。你可以使用 file
将 html 文件读入数组,每个新行都是数组中的另一个条目。然后对另一个 html 文件执行相同的操作。然后你可以去搜索第一个标签(又名:以 <
开头的东西)并阅读该行的其余部分直到 >
.然后去另一个 html 文件中搜索相同的标签,计算该标 checkout 现的次数。冲洗并重复。
关于c# - html 文档比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17673217/