问题描述:

There is much info about opposite situation, when people try to have stuff in HTML, that is visible to Google bots, but not visible to users, in my case, I need opposite thing - to hide some of the html from google bot. The question would be how?

Flash is not an answer,

Would prefer not to use fancy ajax things also (mainly because I need it right away, not on document ready),

Also robots.txt is not an answer, because it works on urls, not parts of the page.

Would any special css/simple javascript work, is any special html tag for this?

网友答案:

Maybe a base64 encoding server side and then decoding on the client side could work?

Code:

<!-- visible to Google -->
<p> Hi, Google Bot! </p>

<!-- not visible from here on -->
<script type="text/javascript">
document.write ("<?php echo base64_encode('<b>hey there, user</b>'); ?>");
</script>

How it looks to the bot:

<!-- visible to Google -->
<p> Hi, Google Bot! </p>

<!-- not visible from here on -->
<script type="text/javascript">
document.write (base64_decode("B9A985350099BC8913=="));
</script>
网友答案:

Create a Div, Load the content of the Div (ajax) from an html file which resides in a directory protected by robots. Example. /index.html

Somewhere on the header. (check http://api.jquery.com/jQuery.ajax/ )

$.ajax({
  url: '/hiddendirfrombots/test.html',
  success: function(data) {
    $('#hiddenfrombots').html(data);
  }
});

... somewhere in the body

<div id="hiddenfrombots"></div>

create a directory "hiddenfrombots" and put the followin in the roots .htaccess

User-agent: *
Disallow: /hiddenfrombots/ 
网友答案:

This should do the Trick:

<!--googleoff: index-->
<p>hide me!</p>
<!--googleon: index-->

For more information check out the link to Googles page that describes it in more depth.

Excluding Unwanted Text from the Index

网友答案:

If you can use PHP, just output your content if not Googlebot:

// if not google
if(!strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) { 
    echo $div;
}

That's how I could solve this issue.

网友答案:

simple, create an image with the text you don't want Google to see

网友答案:
  • Load your content via an Ajax call
  • But create a JS file (e.g.: noGoogleBot.js) that contains the function that implements the ajax call:

    $.ajax({
      url: 'anything.html',
      success: function(data) {
        $('#anywhere').html(data);
      }
    });
    

Then in your robots.txt

User-agent: *
Disallow: /noGoogleBot.js

So all the divs that are loaded using the function in noGoogleBot will be blocked. Googlebot (or any other crawler) will ignore the content of noGoogleBot.js.

相关阅读:
Top