我一直在看这篇文章:Hide links from Google via JavaScript 。我想实现相同的目标:屏蔽网址以防止谷歌抓取,但就我而言,我有外部网址。我希望当我的客户点击这些网址时,他们可以使用这些网址,但谷歌不能抓取这些网址。
这是我到目前为止所拥有的:
<template>
<span href="https://www.w3schools.com/" @click="linkAction($event)">
Link to W3Schools
</span>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
@Component
export default class MainContent extends Vue {
linkAction(e:any): any {
window.location = this.rot13(e.target.getAttribute('href'));
}
rot13(s: any): any {
return (s || this)
.split('')
.map(function(_: any) {
if (!_.match(/[A-za-z]/)) {
return _;
}
const c = Math.floor(_.charCodeAt(0) / 97);
const k = (_.toLowerCase().charCodeAt(0) - 83) % 26 || 26;
return String.fromCharCode(k + (c === 0 ? 64 : 96));
})
.join('');
}
}
</script>
当我检查它时,我仍然看到href,并且我认为谷歌仍然会抓取这些内容并将其编入索引。希望获得有关如何实现这一目标的一些帮助。
最佳答案
通过 <a href>
以外的元素导航使用会导致挫败感。当您中键单击某个链接时,您希望它在新选项卡中打开,但对于不在页面上的链接则不然。
如果您确实想躲避机器人,请使用以下内容:
- 定义链接元素
<a hidden-href="xxx" href="#">.......</a>
- 添加
mouseover
的监听器&focus
(也可能触摸) - 交互时填写
href
与hidden-href
.
可以选择清理上行链路。这可能是不需要的,因为爬虫不会在交互时重新爬行页面...
<小时/>你想与 Google、Bing 等竞争吗?如果您通过 robots.txt
善意地询问他们,他们可能不会关注您的链接。 ,或rel="nofollow"
.
关于javascript - 如何使用哈希来屏蔽外部 URL 不被抓取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59863187/