0

对于包含大量内容的页面,我最近开始喜欢使用 css :target 来仅显示所需的内容。代码可能如下所示:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Test Page</title>
    <style type="text/css">
    body {font-family:sans-serif;}
    #some-content>*,
    #some-content>*:target ~ h2:last-of-type,
    #some-content>*:target ~ h2:last-of-type+* { display: none; }

    #some-content>h2:target,
    #some-content>h2:target+*,
    #some-content>h2:last-of-type,
    #some-content>h2:last-of-type+* { display: block; }
    </style>
</head>
<body>
    <h1>Test Page</h1>
    <ol>
        <li><a href="#test-1">First link</a></li>
        <li><a href="#test-2">Second link</a></li>
        <li><a href="#test-3">Third link</a></li>
        <li><a href="#test-4">Fourth link</a></li>
        <li><a href="#test-5">Fifth link</a></li>
    </ol>
    <div id="some-content">
        <h2 id="test-1">First header</h2>
        <p>First content</p>
        <h2 id="test-2">Second header</h2>
        <p>Second content</p>
        <h2 id="test-3">Third header</h2>
        <p>Third content</p>
        <h2 id="test-4">Fourth header</h2>
        <p>Fourth content</p>
        <h2 id="test-5">Fifth header</h2>
        <p>Fifth content</p>
    </div>
</body>
</html>

我的问题是双重的:

  1. 现代蜘蛛是否遵循锚链接?
  2. 如果不是,是否只有最后一个 h2 及其下一个兄弟姐妹会被蜘蛛?
4

1 回答 1

2

作为一般规则,蜘蛛不解析 CSS。他们所做的 CSS 解析通常与寻找可能的隐藏display:none和其他技巧有关。但是仅仅使用这些 CSS 规则本身并不会给网站带来麻烦,因为这些规则有很多合法用途。只有当它们被用于伪装或其他黑帽搜索引擎优化时,才会受到惩罚。

因此,如果您可以在 HTML 中找到内容,并且它不是由 CSS 或 JavaScript 创建的,那么蜘蛛程序将找到并索引该内容。如果它是由 JavaScript 或 CSS 动态创建的,那么蜘蛛将无法找到它。(Google 的可抓取 Ajax 确实可以与 Google 一起使用,但这是构建网站的一种非常糟糕的方式)。

于 2011-08-04T15:46:12.153 回答