How to tell google bot to skip part of HTML?

2020-03-19 01:28发布

问题:

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?

回答1:

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>


回答2:

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/ 


回答3:

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



回答4:

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.



回答5:

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



回答6:

  • 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.



标签: html css seo